From 2425a6b6dbc393ad6003de90c3e7eeac7691c936 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Wed, 15 May 2024 17:43:44 +0200 Subject: [PATCH 1/9] tidy static-app.psgi --- static-app.psgi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/static-app.psgi b/static-app.psgi index 96794b8426..b3e8dad39d 100644 --- a/static-app.psgi +++ b/static-app.psgi @@ -1,9 +1,9 @@ use strict; use warnings; -use Plack::Builder qw( builder enable mount ); -use Plack::App::Proxy; -use File::Basename (); -use Config::ZOMG (); +use Plack::Builder qw( builder enable mount ); +use Plack::App::Proxy (); +use File::Basename (); +use Config::ZOMG (); my $root_dir; BEGIN { $root_dir = File::Basename::dirname(__FILE__); } From 5683328f91912ed592d9c43212fa83d7f49f338f Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Wed, 15 May 2024 17:44:49 +0200 Subject: [PATCH 2/9] tidy codecov.yml --- codecov.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/codecov.yml b/codecov.yml index be10c07933..ca1311dd33 100644 --- a/codecov.yml +++ b/codecov.yml @@ -2,10 +2,10 @@ comment: layout: 'diff, files' behavior: default - require_changes: true # if true: only post the comment if coverage changes - require_base: false # [true :: must have a base report to post] - require_head: true # [true :: must have a head report to post] - hide_project_coverage: false # [true :: only show coverage on the git diff] + require_changes: true # if true: only post the comment if coverage changes + require_base: false # [true :: must have a base report to post] + require_head: true # [true :: must have a head report to post] + hide_project_coverage: false # [true :: only show coverage on the git diff] coverage: status: patch: From 7893edb17339f47797073603e53223b659e0858d Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Mon, 13 May 2024 21:16:23 +0200 Subject: [PATCH 3/9] use /app/ rather than per-repo root directory for docker build --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index ce48e1e77a..293f7791da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,7 @@ RUN \ apt-get satisfy -y -f --no-install-recommends 'libcmark-dev (>= 0.30.2)' EOT -WORKDIR /metacpan-web/ +WORKDIR /app/ COPY cpanfile cpanfile.snapshot ./ RUN \ @@ -47,8 +47,8 @@ EOT RUN mkdir var && chown metacpan:users var -ENV PERL5LIB="/metacpan-web/local/lib/perl5" -ENV PATH="/metacpan-web/local/bin:${PATH}" +ENV PERL5LIB="/app/local/lib/perl5" +ENV PATH="/app/local/bin:${PATH}" COPY *.md app.psgi *.conf ./ COPY bin bin From bce6922ab7c9a2040154337e117f4ec31e8a6346 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Mon, 13 May 2024 21:17:15 +0200 Subject: [PATCH 4/9] get closer to standardizing the actions setup Update the GitHub Actions configs to try to get closer to a standard setup we can use across multiple repos. Switch from jamestrousdale/github-app-jwt-token to actions/create-github-app-token. Should be more trustworthy and likely better maintained. Use docker/build-push-action for building docker images rather than running the commands manually. Use docker/metadata-action to provide extra metadata, as well as picking the tags we will push. This allows combining the 'deployment' and 'production' build workflows. Update the perl and node versions used when testing without Docker to match the versions used in Docker. --- .github/workflows/automerge.yml | 8 +-- .github/workflows/build-container.yml | 68 +++++++++++++++++++ .../workflows/build-deployment-container.yml | 32 --------- .../workflows/build-production-container.yml | 47 ------------- .github/workflows/test.yml | 20 +++--- .github/workflows/update-snapshot.yml | 10 +-- 6 files changed, 88 insertions(+), 97 deletions(-) create mode 100644 .github/workflows/build-container.yml delete mode 100644 .github/workflows/build-deployment-container.yml delete mode 100644 .github/workflows/build-production-container.yml diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 97241d70c7..1be47e8079 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -1,4 +1,4 @@ -name: Maybe Enable Auto-Merge +name: Enable Auto-Merge For metacpan-automation on: pull_request_target: types: [opened] @@ -9,12 +9,12 @@ jobs: if: github.event.pull_request.user.login == 'metacpan-automation[bot]' steps: - name: Generate Auth Token - id: auth-token - uses: jamestrousdale/github-app-jwt-token@0.1.4 + uses: actions/create-github-app-token@v1 + id: app-token with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} - uses: peter-evans/enable-pull-request-automerge@v3 with: - token: ${{ steps.auth-token.outputs.access-token }} + token: ${{ steps.app-token.outputs.token }} pull-request-number: ${{ github.event.pull_request.number }} diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml new file mode 100644 index 0000000000..0708337da2 --- /dev/null +++ b/.github/workflows/build-container.yml @@ -0,0 +1,68 @@ +name: Build container +on: + push: + branches: + - master + - staging + - prod + pull_request: + branches: + - master + workflow_dispatch: +jobs: + docker: + runs-on: ubuntu-22.04 + name: Docker Build and Push + steps: + - name: Generate Auth Token + uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ secrets.APP_ID }} + private-key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_USER }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - uses: actions/checkout@v4 + with: + token: ${{ steps.app-token.outputs.token }} + - name: Build test image + id: docker-build-test + uses: docker/build-push-action@v5 + with: + target: test + push: false + load: true + - name: Run Perl tests + run: docker run -i ${{ steps.docker-build-test.outputs.imageid }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ github.repository }} + flavor: | + latest=false + tags: | + type=sha,format=long,priority=2000 + type=ref,event=branch + type=ref,event=pr + type=raw,value=latest,enable={{is_default_branch}} + - name: Build and push + uses: docker/build-push-action@v5 + with: + push: true + tags: ${{ steps.meta.outputs.tags }} + annotations: ${{ steps.meta.outputs.annotations }} + - name: Update deployed image + if: ${{ contains( fromJSON(steps.meta.outputs.json).tags, format('{0}:latest', github.repository)) }} + uses: benc-uk/workflow-dispatch@v1 + with: + repo: metacpan/metacpan-k8s + ref: main + workflow: set-image.yml + token: ${{ steps.app-token.outputs.token }} + inputs: '{ "app": "web", "environment": "prod", "base-tag": "${{ github.repository }}:latest", "tag": "${{ fromJSON(steps.meta.outputs.json).tags[0] }}" }' diff --git a/.github/workflows/build-deployment-container.yml b/.github/workflows/build-deployment-container.yml deleted file mode 100644 index fd77e96252..0000000000 --- a/.github/workflows/build-deployment-container.yml +++ /dev/null @@ -1,32 +0,0 @@ ---- -name: Build deployment container -on: - push: - branches: - - prod - - staging - workflow_dispatch: -jobs: - docker: - runs-on: ubuntu-22.04 - name: Docker Push - steps: - - uses: actions/checkout@v4 - - name: Log in to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_HUB_USER }} - password: ${{ secrets.DOCKER_HUB_TOKEN }} - - name: Build test image - uses: docker/build-push-action@v5 - with: - tags: metacpan/metacpan-web:test - target: test - push: false - - name: Run Perl tests - run: docker run -i metacpan/metacpan-web:test - - name: Build and push - uses: docker/build-push-action@v5 - with: - push: true - tags: metacpan/metacpan-web:${{ github.sha }} diff --git a/.github/workflows/build-production-container.yml b/.github/workflows/build-production-container.yml deleted file mode 100644 index e6faf129e1..0000000000 --- a/.github/workflows/build-production-container.yml +++ /dev/null @@ -1,47 +0,0 @@ ---- -name: Build production container -on: - push: - branches: - - master - workflow_dispatch: -jobs: - docker: - runs-on: ubuntu-22.04 - name: Docker Push - steps: - - name: Generate Auth Token - id: auth-token - uses: jamestrousdale/github-app-jwt-token@0.1.4 - with: - app-id: ${{ secrets.APP_ID }} - private-key: ${{ secrets.APP_PRIVATE_KEY }} - - uses: actions/checkout@v4 - with: - token: ${{ steps.auth-token.outputs.access-token }} - - name: Log in to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_HUB_USER }} - password: ${{ secrets.DOCKER_HUB_TOKEN }} - - name: Build test image - uses: docker/build-push-action@v5 - with: - tags: metacpan/metacpan-web:test - target: test - push: false - - name: Run Perl tests - run: docker run -i metacpan/metacpan-web:test - - name: Build and push - uses: docker/build-push-action@v5 - with: - push: true - tags: metacpan/metacpan-web:latest,metacpan/metacpan-web:${{ github.sha }} - - name: Update deployed image - uses: aurelien-baudet/workflow-dispatch@v2 - with: - repo: metacpan/metacpan-k8s - workflow: set-image.yml - token: ${{ steps.auth-token.outputs.access-token }} - ref: main - inputs: '{ "app": "web", "environment": "prod", "base-tag": "metacpan/metacpan-web:latest", "tag": "metacpan/metacpan-web:${{ github.sha }}" }' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 955cada7f1..f15410d1c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,13 +14,15 @@ jobs: runs-on: ubuntu-22.04 name: Docker steps: - - uses: actions/checkout@v4 - - name: docker build - run: docker build . --target test -t metacpan/metacpan-web:latest - - name: run Perl tests - run: > - docker run -i metacpan/metacpan-web - carton exec prove -lr --jobs 2 t + - name: Build test image + id: docker-build-test + uses: docker/build-push-action@v5 + with: + target: test + push: false + load: true + - name: Run Perl tests + run: docker run -i ${{ steps.docker-build-test.outputs.imageid }} test: runs-on: ubuntu-20.04 name: Dockerless @@ -28,7 +30,7 @@ jobs: fail-fast: false matrix: perl-version: - - '5.30' + - '5.36' resolver: - snapshot - metacpan @@ -45,7 +47,7 @@ jobs: if: matrix.resolver != 'snapshot' - uses: actions/setup-node@v4 with: - node-version: '18' + node-version: '22' - run: npm install - run: apt-get update && apt-get -y install libcmark-dev - name: Install Carton diff --git a/.github/workflows/update-snapshot.yml b/.github/workflows/update-snapshot.yml index ab3816670d..e7ceee2acd 100644 --- a/.github/workflows/update-snapshot.yml +++ b/.github/workflows/update-snapshot.yml @@ -8,8 +8,8 @@ jobs: runs-on: 'ubuntu-20.04' steps: - name: Generate Auth Token - id: auth-token - uses: jamestrousdale/github-app-jwt-token@0.1.4 + uses: actions/create-github-app-token@v1 + id: app-token with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} @@ -17,10 +17,10 @@ jobs: name: Set up git user uses: haarg/setup-git-user@v1 with: - jwt: ${{ steps.auth-token.outputs.jwt }} + app: ${{ steps.app-token.outputs.app-slug }} - uses: actions/checkout@v4 with: - token: ${{ steps.auth-token.outputs.access-token }} + token: ${{ steps.app-token.outputs.token }} - name: Set up installation local::lib run: | mkdir -p $RUNNER_TEMP/perl5/bin @@ -69,7 +69,7 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@v6 with: - token: ${{ steps.auth-token.outputs.access-token }} + token: ${{ steps.app-token.outputs.token }} commit-message: Update cpanfile.snapshot title: Update cpanfile.snapshot author: ${{ steps.git-user.outputs.user-full }} From 4743f799027427ec523ab0bc7c039d8dba67fb57 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Mon, 13 May 2024 21:22:07 +0200 Subject: [PATCH 5/9] use codecov/codecov-action for uploading coverage reports Devel::Cover::Report::Codecov is deprecated. Instead, use the codecovbash report type to generate the json to upload, and upload it using codecov/codecov-action. --- .github/workflows/test.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f15410d1c2..7e0acf7689 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -77,7 +77,6 @@ jobs: with: install: | Devel::Cover - Devel::Cover::Report::Codecov Devel::Cover::Report::Codecovbash sudo: false - name: Run tests with coverage @@ -85,11 +84,15 @@ jobs: run: carton exec prove -lr --jobs 2 t env: HARNESS_PERL_SWITCHES: -MDevel::Cover=+ignore,^t/ - - name: Upload coverage reports to Codecov + - name: Generate Codecov report if: matrix.resolver == 'snapshot' - run: cover -report codecov - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + run: cover -report codecovbash + - uses: codecov/codecov-action@v4 + if: matrix.resolver == 'snapshot' + with: + fail_ci_if_error: true + file: ./cover_db/codecov.json + token: ${{ secrets.CODECOV_TOKEN }} - name: Install precious run: ./bin/install-precious /usr/local/bin - name: Install perlimports From 78167a58c8bb3c274dd11a829ab8281616421e5e Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Wed, 15 May 2024 01:42:49 +0200 Subject: [PATCH 6/9] add labels to docker image --- .github/workflows/build-container.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml index 0708337da2..cbbae07fb2 100644 --- a/.github/workflows/build-container.yml +++ b/.github/workflows/build-container.yml @@ -51,11 +51,14 @@ jobs: type=ref,event=branch type=ref,event=pr type=raw,value=latest,enable={{is_default_branch}} + env: + DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index - name: Build and push uses: docker/build-push-action@v5 with: push: true tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} annotations: ${{ steps.meta.outputs.annotations }} - name: Update deployed image if: ${{ contains( fromJSON(steps.meta.outputs.json).tags, format('{0}:latest', github.repository)) }} From 84cf70e75bde72d41324e63575cbddb9d17f7ae3 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Thu, 16 May 2024 22:08:13 +0200 Subject: [PATCH 7/9] run npm scripts using npx --- precious.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/precious.toml b/precious.toml index 7e98b357df..f3d5985b6d 100644 --- a/precious.toml +++ b/precious.toml @@ -46,7 +46,7 @@ ignore-stderr = [ type = "both" include = "**/*.md" cmd = [ - "./node_modules/.bin/prettier", + "npx", "-s", "prettier", "--no-config", "--print-width", "80", "--prose-wrap", "always", @@ -61,7 +61,7 @@ ignore-stderr = [ "Code style issues" ] type = "both" include = "**/*.yml" cmd = [ - "./node_modules/.bin/prettier", + "npx", "-s", "prettier", "--no-config", "--single-quote", ] From caebd123cba6d072c871a2dd9d72d0c9c3f76922 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Fri, 17 May 2024 00:28:46 +0200 Subject: [PATCH 8/9] remove some cpm arguments that are already the defaults --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7e0acf7689..18307db51d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -62,8 +62,6 @@ jobs: sudo: false args: > --resolver ${{ matrix.resolver }} - --show-build-log-on-failure - --local-lib-contained=local - name: Build assets run: npm run build - name: Run tests without coverage From cf6def93b3efefc5b6ae766691e8ba4cfdac53af Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Mon, 13 May 2024 23:08:19 +0200 Subject: [PATCH 9/9] use separate check for code formatting --- .github/workflows/test.yml | 49 ++++++++++++++++++--------- .github/workflows/update-snapshot.yml | 1 + cpanfile | 27 ++++++++------- 3 files changed, 49 insertions(+), 28 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 18307db51d..3708a617ef 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,39 @@ on: workflow_dispatch: jobs: + code-formatting: + runs-on: ubuntu-22.04 + name: Code Formatting + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Fetch base ref + if: ${{ github.event.pull_request }} + run: git fetch origin ${{ github.base_ref }}:upstream + - run: npm install + - name: Install Carton + uses: perl-actions/install-with-cpm@v1 + with: + install: Carton + - name: Install CPAN deps + uses: perl-actions/install-with-cpm@v1 + with: + cpanfile: 'cpanfile' + args: > + --resolver=snapshot + --without-runtime + --without-test + --without-build + --with-develop + - name: Install precious + run: ./bin/install-precious /usr/local/bin + - name: Lint modified files + if: ${{ github.event.pull_request }} + run: precious lint --git-diff-from upstream + - name: Lint all files + if: ${{ ! github.event.pull_request }} + run: precious lint --all docker: runs-on: ubuntu-22.04 name: Docker @@ -40,8 +73,6 @@ jobs: DEVEL_COVER_OPTIONS: '-ignore,^local/' steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 if: matrix.resolver == 'snapshot' - uses: actions/checkout@v4 if: matrix.resolver != 'snapshot' @@ -91,17 +122,3 @@ jobs: fail_ci_if_error: true file: ./cover_db/codecov.json token: ${{ secrets.CODECOV_TOKEN }} - - name: Install precious - run: ./bin/install-precious /usr/local/bin - - name: Install perlimports - run: cpm install -g App::perlimports - if: matrix.resolver == 'snapshot' - - name: Fetch master - run: git fetch origin master:master - if: github.ref != 'refs/heads/master' && matrix.resolver == 'snapshot' - - name: Lint files in diff (branch) - run: precious lint -d master - if: github.ref != 'refs/heads/master' && matrix.resolver == 'snapshot' - - name: Lint all files (master) - run: precious lint --all - if: github.ref == 'refs/heads/master' && matrix.resolver == 'snapshot' diff --git a/.github/workflows/update-snapshot.yml b/.github/workflows/update-snapshot.yml index e7ceee2acd..8166e457c5 100644 --- a/.github/workflows/update-snapshot.yml +++ b/.github/workflows/update-snapshot.yml @@ -64,6 +64,7 @@ jobs: --resolver metacpan --show-build-log-on-failure --local-lib-contained=local + --with-develop - name: Maybe update cpanfile.snapshot run: carton - name: Create Pull Request diff --git a/cpanfile b/cpanfile index a0fe98d956..eb20e46120 100644 --- a/cpanfile +++ b/cpanfile @@ -34,7 +34,6 @@ requires 'Gazelle'; requires 'Getopt::Long::Descriptive'; requires 'HTML::Escape'; requires 'HTML::Restrict', '2.2.2'; -requires 'HTML::Tree'; requires 'HTTP::Message::PSGI'; requires 'HTTP::Request'; requires 'HTTP::Request::Common'; @@ -90,14 +89,18 @@ requires 'With::Roles', '0.001002'; requires 'WWW::Form::UrlEncoded::XS'; requires 'XML::FeedPP'; -# Test dependencies -requires 'aliased', '0.34'; -requires 'App::Prove'; -requires 'Perl::Critic', '1.136'; -requires 'Perl::Tidy' => '20230909'; -requires 'Test::Code::TidyAll'; -requires 'Test::More', '0.96'; -requires 'Test::Needs'; -requires 'Test::Perl::Critic'; -requires 'Test::Warnings'; -requires 'Test::XPath', '0.15'; +on test => sub { + requires 'App::Prove'; + requires 'HTML::Tree'; + requires 'Test::More', '0.96'; + requires 'Test::Warnings'; + requires 'Test::XPath', '0.15'; + requires 'aliased', '0.34'; +}; + +on develop => sub { + requires 'App::perlimports'; + requires 'Perl::Critic', '1.136'; + requires 'Perl::Tidy' => '20230909'; + requires 'Test::Vars'; +};