From ec54e00f6a345be993aa88a277677dccd0da6543 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Thu, 17 Oct 2024 11:07:49 +0400 Subject: [PATCH 1/7] add action to deploy assets from PR and delete them when the PR is closed --- .github/workflows/deploy-pr.yml | 41 +++++++++++++++++++++++++++++++++ .github/workflows/pr-merged.yml | 27 ++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .github/workflows/deploy-pr.yml create mode 100644 .github/workflows/pr-merged.yml diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml new file mode 100644 index 00000000..6303d32d --- /dev/null +++ b/.github/workflows/deploy-pr.yml @@ -0,0 +1,41 @@ +on: + pull_request_target: + types: [opened, edited, reopened, synchronize] + +jobs: + build_css: + runs-on: ubuntu-latest + env: + source: public/dist/assets + destination: test/assets/website-2021/pr-${{ github.event.number }}/ + steps: + - name: Checkout source Git branch + uses: actions/checkout@v2 + + - name: Use Node.js + uses: actions/setup-node@v2 + with: + node-version: '16' + + - name: Install npm modules + run: npm install + + - name: compile assets + run: npm run build + + - name: Upload to cdn.w3.org bucket + if: success() + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: 'us-east-1' + run: + aws s3 sync --no-progress ${{ env.source }} s3://cdn-dev.w3.org/${{ env.destination }} + + - name: Purge cache for www.w3.org + uses: nathanvaughn/actions-cloudflare-purge@master + if: success() + with: + cf_zone: ${{ secrets.CLOUDFLARE_ZONE }} + cf_auth: ${{ secrets.CLOUDFLARE_CACHEPURGE_TOKEN }} + prefixes: www.w3.org/${{ env.destination }} diff --git a/.github/workflows/pr-merged.yml b/.github/workflows/pr-merged.yml new file mode 100644 index 00000000..0ccd097c --- /dev/null +++ b/.github/workflows/pr-merged.yml @@ -0,0 +1,27 @@ +on: + pull_request_target: + types: + - closed + +jobs: + delete_assets: + runs-on: ubuntu-latest + env: + destination: test/assets/website-2021/pr-${{ github.event.number }}/ + steps: + - name: Delete PR assets from the cdn.w3.org bucket + if: success() + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: 'us-east-1' + run: + aws s3 rm --recursive s3://cdn-dev.w3.org/${{ env.destination }} + + - name: Purge cache for www.w3.org + uses: nathanvaughn/actions-cloudflare-purge@master + if: success() + with: + cf_zone: ${{ secrets.CLOUDFLARE_ZONE }} + cf_auth: ${{ secrets.CLOUDFLARE_CACHEPURGE_TOKEN }} + prefixes: www.w3.org/${{ env.destination }} From ad3115c3588e747d8ebc2fbba9c8d6c765692ba9 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Thu, 17 Oct 2024 12:01:44 +0400 Subject: [PATCH 2/7] use cdn.w3.org --- .github/workflows/deploy-pr.yml | 7 +++++-- .github/workflows/pr-merged.yml | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 6303d32d..4cd24d19 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -7,10 +7,13 @@ jobs: runs-on: ubuntu-latest env: source: public/dist/assets - destination: test/assets/website-2021/pr-${{ github.event.number }}/ + destination: assets/website-2021/pr-${{ github.event.number }}/ steps: - name: Checkout source Git branch uses: actions/checkout@v2 + with: + ref: ${{github.event.pull_request.head.ref}} + persist-credentials: false - name: Use Node.js uses: actions/setup-node@v2 @@ -30,7 +33,7 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_REGION: 'us-east-1' run: - aws s3 sync --no-progress ${{ env.source }} s3://cdn-dev.w3.org/${{ env.destination }} + aws s3 sync --no-progress ${{ env.source }} s3://cdn.w3.org/${{ env.destination }} - name: Purge cache for www.w3.org uses: nathanvaughn/actions-cloudflare-purge@master diff --git a/.github/workflows/pr-merged.yml b/.github/workflows/pr-merged.yml index 0ccd097c..00124923 100644 --- a/.github/workflows/pr-merged.yml +++ b/.github/workflows/pr-merged.yml @@ -7,7 +7,7 @@ jobs: delete_assets: runs-on: ubuntu-latest env: - destination: test/assets/website-2021/pr-${{ github.event.number }}/ + destination: assets/website-2021/pr-${{ github.event.number }}/ steps: - name: Delete PR assets from the cdn.w3.org bucket if: success() @@ -16,7 +16,7 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_REGION: 'us-east-1' run: - aws s3 rm --recursive s3://cdn-dev.w3.org/${{ env.destination }} + aws s3 rm --recursive s3://cdn.w3.org/${{ env.destination }} - name: Purge cache for www.w3.org uses: nathanvaughn/actions-cloudflare-purge@master From dd3a5ddb4171d6de3948bb4485b8a8d50c214240 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Thu, 17 Oct 2024 12:08:07 +0400 Subject: [PATCH 3/7] better use cdn-dev.w3.org for security reasons --- .github/workflows/deploy-pr.yml | 12 ++---------- .github/workflows/pr-merged.yml | 12 ++---------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 4cd24d19..dc3cdd83 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -26,19 +26,11 @@ jobs: - name: compile assets run: npm run build - - name: Upload to cdn.w3.org bucket + - name: Upload to cdn-dev.w3.org bucket if: success() env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_REGION: 'us-east-1' run: - aws s3 sync --no-progress ${{ env.source }} s3://cdn.w3.org/${{ env.destination }} - - - name: Purge cache for www.w3.org - uses: nathanvaughn/actions-cloudflare-purge@master - if: success() - with: - cf_zone: ${{ secrets.CLOUDFLARE_ZONE }} - cf_auth: ${{ secrets.CLOUDFLARE_CACHEPURGE_TOKEN }} - prefixes: www.w3.org/${{ env.destination }} + aws s3 sync --no-progress ${{ env.source }} s3://cdn-dev.w3.org/${{ env.destination }} diff --git a/.github/workflows/pr-merged.yml b/.github/workflows/pr-merged.yml index 00124923..ef4f4742 100644 --- a/.github/workflows/pr-merged.yml +++ b/.github/workflows/pr-merged.yml @@ -9,19 +9,11 @@ jobs: env: destination: assets/website-2021/pr-${{ github.event.number }}/ steps: - - name: Delete PR assets from the cdn.w3.org bucket + - name: Delete PR assets from the cdn-dev.w3.org bucket if: success() env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_REGION: 'us-east-1' run: - aws s3 rm --recursive s3://cdn.w3.org/${{ env.destination }} - - - name: Purge cache for www.w3.org - uses: nathanvaughn/actions-cloudflare-purge@master - if: success() - with: - cf_zone: ${{ secrets.CLOUDFLARE_ZONE }} - cf_auth: ${{ secrets.CLOUDFLARE_CACHEPURGE_TOKEN }} - prefixes: www.w3.org/${{ env.destination }} + aws s3 rm --recursive s3://cdn-dev.w3.org/${{ env.destination }} From ea81939618c3ce2ba5814602d011b82075dc12d5 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Wed, 8 Jan 2025 19:28:18 +0400 Subject: [PATCH 4/7] use a different destination folder for PR --- .github/workflows/deploy-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index dc3cdd83..144cf2c3 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest env: source: public/dist/assets - destination: assets/website-2021/pr-${{ github.event.number }}/ + destination: assets/website-2021-dev/pr-${{ github.event.number }}/ steps: - name: Checkout source Git branch uses: actions/checkout@v2 From c657341aa94db8371a3962c845b9950e856c2abf Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Wed, 8 Jan 2025 19:34:14 +0400 Subject: [PATCH 5/7] use a different destination folder for PR --- .github/workflows/pr-merged.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-merged.yml b/.github/workflows/pr-merged.yml index ef4f4742..85998e2d 100644 --- a/.github/workflows/pr-merged.yml +++ b/.github/workflows/pr-merged.yml @@ -7,7 +7,7 @@ jobs: delete_assets: runs-on: ubuntu-latest env: - destination: assets/website-2021/pr-${{ github.event.number }}/ + destination: assets/website-2021-dev/pr-${{ github.event.number }}/ steps: - name: Delete PR assets from the cdn-dev.w3.org bucket if: success() From 99d4058e3b296c30e92d7c769e5bd4348e39e366 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Wed, 8 Jan 2025 19:35:17 +0400 Subject: [PATCH 6/7] rename action --- .github/workflows/{pr-merged.yml => pr-closed.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{pr-merged.yml => pr-closed.yml} (100%) diff --git a/.github/workflows/pr-merged.yml b/.github/workflows/pr-closed.yml similarity index 100% rename from .github/workflows/pr-merged.yml rename to .github/workflows/pr-closed.yml From 8e9af626dbea3024cb25d4818825f7e749254012 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Thu, 9 Jan 2025 10:51:27 +0400 Subject: [PATCH 7/7] run workflow only on pull_request --- .github/workflows/deploy-pr.yml | 2 +- .github/workflows/pr-closed.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 144cf2c3..b34dd7ce 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -1,5 +1,5 @@ on: - pull_request_target: + pull_request: types: [opened, edited, reopened, synchronize] jobs: diff --git a/.github/workflows/pr-closed.yml b/.github/workflows/pr-closed.yml index 85998e2d..77b98b00 100644 --- a/.github/workflows/pr-closed.yml +++ b/.github/workflows/pr-closed.yml @@ -1,5 +1,5 @@ on: - pull_request_target: + pull_request: types: - closed