From 44affa4cae66b90505b4fc89fd6a4a6301f2621f Mon Sep 17 00:00:00 2001 From: hazzuk Date: Sat, 7 Dec 2024 19:10:26 +0000 Subject: [PATCH 01/11] chore(github): create cloudflare deploy step --- .github/workflows/build.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b2bcb1fb83a..3312c7913fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,4 +59,21 @@ jobs: uses: actions/upload-artifact@v4 with: name: webapp - path: dist/elecord.tar.gz \ No newline at end of file + path: dist/elecord.tar.gz + deploy: + needs: build + name: Deploy webapp + runs-on: ubuntu-24.04 + steps: + - run: mkdir -p pages + + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: webapp + path: pages + + - name: extract tarball + run: tar -xvzf pages/elecord.tar.gz + + - run: ls From 5e9a892d233458e5d85dd5bbe50ebea0d9ca1a87 Mon Sep 17 00:00:00 2001 From: hazzuk Date: Sat, 7 Dec 2024 19:25:43 +0000 Subject: [PATCH 02/11] chore(github): add cf pages command --- .github/workflows/build.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3312c7913fa..07dc57d67fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,3 +77,10 @@ jobs: run: tar -xvzf pages/elecord.tar.gz - run: ls + + - name: Deploy to Cloudflare Pages + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: pages deploy elecord-* --project-name=elecord-web \ No newline at end of file From 8caace0e6f2cacafffb65516bdc73d1a9086e702 Mon Sep 17 00:00:00 2001 From: hazzuk Date: Sat, 7 Dec 2024 19:37:27 +0000 Subject: [PATCH 03/11] chore(github): fix webapp dist location --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07dc57d67fa..b0f2331e8bd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -76,6 +76,8 @@ jobs: - name: extract tarball run: tar -xvzf pages/elecord.tar.gz + - run: mv elecord-*/ elecord + - run: ls - name: Deploy to Cloudflare Pages @@ -83,4 +85,4 @@ jobs: with: apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - command: pages deploy elecord-* --project-name=elecord-web \ No newline at end of file + command: pages deploy elecord --project-name=elecord-web \ No newline at end of file From 085b625d1432fe808df0d47a5ce85579769b9931 Mon Sep 17 00:00:00 2001 From: hazzuk Date: Sat, 7 Dec 2024 20:42:44 +0000 Subject: [PATCH 04/11] chore(github): simplify deployment steps --- .github/workflows/build.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b0f2331e8bd..3381ba4467b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,24 +65,21 @@ jobs: name: Deploy webapp runs-on: ubuntu-24.04 steps: - - run: mkdir -p pages - - name: Download Artifact uses: actions/download-artifact@v4 with: name: webapp - path: pages + path: . - - name: extract tarball - run: tar -xvzf pages/elecord.tar.gz - - - run: mv elecord-*/ elecord + - name: Extract tarball + run: tar -xvzf elecord.tar.gz - - run: ls + - name: Move to dist + run: mv elecord-*/ dist - name: Deploy to Cloudflare Pages uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - command: pages deploy elecord --project-name=elecord-web \ No newline at end of file + command: pages deploy dist --project-name=elecord-web \ No newline at end of file From 5ccda9e785a03d12e671ad7b70c488eab3338036 Mon Sep 17 00:00:00 2001 From: hazzuk Date: Sat, 7 Dec 2024 20:51:20 +0000 Subject: [PATCH 05/11] chore(github): print deploy urls --- .github/workflows/build.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3381ba4467b..317afc800d4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -82,4 +82,13 @@ jobs: with: apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - command: pages deploy dist --project-name=elecord-web \ No newline at end of file + command: pages deploy dist --project-name=elecord-web + - name: print deployment-url + env: + DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }} + run: echo $DEPLOYMENT_URL + + - name: print pages-deployment-alias-url + env: + DEPLOYMENT_ALIAS_URL: ${{ steps.deploy.outputs.pages-deployment-alias-url }} + run: echo $DEPLOYMENT_ALIAS_URL \ No newline at end of file From df08f19c102fcb7e97762617acba02ee292e79cc Mon Sep 17 00:00:00 2001 From: hazzuk Date: Sun, 8 Dec 2024 09:14:49 +0000 Subject: [PATCH 06/11] chore(github): comment deploy url --- .github/workflows/build.yml | 60 ++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 317afc800d4..a683f96cede 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -60,11 +60,13 @@ jobs: with: name: webapp path: dist/elecord.tar.gz + deploy: needs: build name: Deploy webapp runs-on: ubuntu-24.04 steps: + # Download and extract the build folder - name: Download Artifact uses: actions/download-artifact@v4 with: @@ -77,18 +79,62 @@ jobs: - name: Move to dist run: mv elecord-*/ dist + # Deploy to Cloudflare using wrangler - name: Deploy to Cloudflare Pages + id: cf uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: pages deploy dist --project-name=elecord-web - name: print deployment-url - env: - DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }} - run: echo $DEPLOYMENT_URL + run: echo ${{ steps.cf.outputs.deployment-url }} + + - run: echo ${{ github.event_name }} + - run: echo ${{ github.event.pull_request.head.sha }} + - run: echo ${{ github.sha }} + - run: echo ${{ github.ref_name }} + - run: echo ${{ github.event.pull_request.number }} + + - name: test logic + if: ${{ github.event_name == 'pull_request_target' && success() }} + run: echo "pass" + + - name: test logic + if: ${{ github.event_name == 'pull_request_target' && failure() }} + run: echo "fail" - - name: print pages-deployment-alias-url - env: - DEPLOYMENT_ALIAS_URL: ${{ steps.deploy.outputs.pages-deployment-alias-url }} - run: echo $DEPLOYMENT_ALIAS_URL \ No newline at end of file + # Update PR status comment with deployment URL + - name: Update status comment (Success) + if: ${{ github.event_name == 'pull_request_target' && success() }} + uses: thollander/actions-comment-pull-request@v3 + with: + GITHUB_TOKEN: ${{ secrets.PR_COMMENTS }} + message: | + ## Cloudflare Pages deployment + + | **Latest commit** | ${{ github.event.pull_request.head.sha || github.sha }} | + |-------------------|:-:| + | **Status** | ✅ Deployed! | + | **Preview URL** | ${{ steps.cf.outputs.deployment-url != '' && steps.cf.outputs.deployment-url || 'Not available' }} | + | **Type** | 🔀 Preview | + pr_number: ${{ github.event.pull_request.number }} + comment_tag: CFPages-deployment + mode: recreate + + - name: Update status comment (Failure) + if: ${{ github.event_name == 'pull_request_target' && failure() }} + uses: thollander/actions-comment-pull-request@v3 + with: + GITHUB_TOKEN: ${{ secrets.PR_COMMENTS }} + message: | + ## Cloudflare Pages deployment + + | **Latest commit** | ${{ github.event.pull_request.head.sha || github.sha }} | + |-------------------|:-:| + | **Status** | ❌ Failure. Check workflow logs for details | + | **Preview URL** | Not available | + | **Type** | 🔀 Preview | + pr_number: ${{ github.event.pull_request.number }} + comment_tag: CFPages-deployment + mode: recreate \ No newline at end of file From 5ea4dc74dfb61ad40526ab3a944bcedab06e0c1f Mon Sep 17 00:00:00 2001 From: hazzuk Date: Sun, 8 Dec 2024 09:41:00 +0000 Subject: [PATCH 07/11] chore(github): fix pr comment --- .github/workflows/build.yml | 46 ++++++++++++------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a683f96cede..16ffba6fe91 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,6 +65,8 @@ jobs: needs: build name: Deploy webapp runs-on: ubuntu-24.04 + permissions: + pull-requests: write steps: # Download and extract the build folder - name: Download Artifact @@ -86,55 +88,37 @@ jobs: with: apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - command: pages deploy dist --project-name=elecord-web - - name: print deployment-url - run: echo ${{ steps.cf.outputs.deployment-url }} - - - run: echo ${{ github.event_name }} - - run: echo ${{ github.event.pull_request.head.sha }} - - run: echo ${{ github.sha }} - - run: echo ${{ github.ref_name }} - - run: echo ${{ github.event.pull_request.number }} - - - name: test logic - if: ${{ github.event_name == 'pull_request_target' && success() }} - run: echo "pass" - - - name: test logic - if: ${{ github.event_name == 'pull_request_target' && failure() }} - run: echo "fail" + command: pages deploy dist --project-name=elecord-web --branch=main # Update PR status comment with deployment URL - - name: Update status comment (Success) - if: ${{ github.event_name == 'pull_request_target' && success() }} + - name: Update status comment (Failure) + if: ${{ github.event_name == 'pull_request' && failure() }} uses: thollander/actions-comment-pull-request@v3 with: - GITHUB_TOKEN: ${{ secrets.PR_COMMENTS }} message: | ## Cloudflare Pages deployment | **Latest commit** | ${{ github.event.pull_request.head.sha || github.sha }} | |-------------------|:-:| - | **Status** | ✅ Deployed! | - | **Preview URL** | ${{ steps.cf.outputs.deployment-url != '' && steps.cf.outputs.deployment-url || 'Not available' }} | + | **Status** | ❌ Failure. Check workflow logs for details | + | **Preview URL** | Not available | | **Type** | 🔀 Preview | - pr_number: ${{ github.event.pull_request.number }} - comment_tag: CFPages-deployment + pr-number: ${{ github.event.pull_request.number }} + comment-tag: CFPages-deployment mode: recreate - - name: Update status comment (Failure) - if: ${{ github.event_name == 'pull_request_target' && failure() }} + - name: Update status comment (Success) + if: ${{ github.event_name == 'pull_request' && success() }} uses: thollander/actions-comment-pull-request@v3 with: - GITHUB_TOKEN: ${{ secrets.PR_COMMENTS }} message: | ## Cloudflare Pages deployment | **Latest commit** | ${{ github.event.pull_request.head.sha || github.sha }} | |-------------------|:-:| - | **Status** | ❌ Failure. Check workflow logs for details | - | **Preview URL** | Not available | + | **Status** | ✅ Deployed! | + | **Preview URL** | ${{ steps.cf.outputs.deployment-url != '' && steps.cf.outputs.deployment-url || 'Not available' }} | | **Type** | 🔀 Preview | - pr_number: ${{ github.event.pull_request.number }} - comment_tag: CFPages-deployment + pr-number: ${{ github.event.pull_request.number }} + comment-tag: CFPages-deployment mode: recreate \ No newline at end of file From e6c21a3d80af81e53bea8dcdfa707f9f71b0c340 Mon Sep 17 00:00:00 2001 From: hazzuk Date: Sun, 8 Dec 2024 10:31:58 +0000 Subject: [PATCH 08/11] chore(github): add comment reactions --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 16ffba6fe91..387859176de 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -105,6 +105,7 @@ jobs: | **Type** | 🔀 Preview | pr-number: ${{ github.event.pull_request.number }} comment-tag: CFPages-deployment + reactions: -1 mode: recreate - name: Update status comment (Success) @@ -121,4 +122,5 @@ jobs: | **Type** | 🔀 Preview | pr-number: ${{ github.event.pull_request.number }} comment-tag: CFPages-deployment + reactions: rocket mode: recreate \ No newline at end of file From 2e36245e418f97e100a328bd58e52e1fda47eb94 Mon Sep 17 00:00:00 2001 From: hazzuk Date: Sun, 8 Dec 2024 10:32:22 +0000 Subject: [PATCH 09/11] chore(github): change pages branch --- .github/workflows/build.yml | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 387859176de..33b76eeb1db 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ name: Build on: pull_request: {} push: - branches: [develop, master] + branches: [release, master] merge_group: types: [checks_requested] # develop pushes and repository_dispatch handled in build_develop.yaml @@ -81,6 +81,23 @@ jobs: - name: Move to dist run: mv elecord-*/ dist + # Set the Cloudflare pages branch + - name: Set Pages branch + run: | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + if [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then + echo "cf_branch=test" >> $GITHUB_ENV + elif [[ "${{ github.event.pull_request.base.ref }}" == "release" ]]; then + echo "cf_branch=preview" >> $GITHUB_ENV + fi + elif [[ "${{ github.event_name }}" == "push" ]]; then + if [[ "${{ github.ref_name }}" == "master" ]]; then + echo "cf_branch=dev" >> $GITHUB_ENV + elif [[ "${{ github.ref_name }}" == "release" ]]; then + echo "cf_branch=main" >> $GITHUB_ENV + fi + fi + # Deploy to Cloudflare using wrangler - name: Deploy to Cloudflare Pages id: cf @@ -88,7 +105,7 @@ jobs: with: apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - command: pages deploy dist --project-name=elecord-web --branch=main + command: pages deploy dist --project-name=elecord-web --branch=${{ env.cf_branch }} # Update PR status comment with deployment URL - name: Update status comment (Failure) @@ -102,12 +119,17 @@ jobs: |-------------------|:-:| | **Status** | ❌ Failure. Check workflow logs for details | | **Preview URL** | Not available | - | **Type** | 🔀 Preview | pr-number: ${{ github.event.pull_request.number }} comment-tag: CFPages-deployment reactions: -1 mode: recreate + - name: Add preview URL + run: | + if [[ "${{ env.cf_branch }}" == "preview" ]]; then + echo -e "cf_preview=https://preview.elecord.app\n" >> $GITHUB_ENV + fi + - name: Update status comment (Success) if: ${{ github.event_name == 'pull_request' && success() }} uses: thollander/actions-comment-pull-request@v3 @@ -118,8 +140,7 @@ jobs: | **Latest commit** | ${{ github.event.pull_request.head.sha || github.sha }} | |-------------------|:-:| | **Status** | ✅ Deployed! | - | **Preview URL** | ${{ steps.cf.outputs.deployment-url != '' && steps.cf.outputs.deployment-url || 'Not available' }} | - | **Type** | 🔀 Preview | + | **URL** | ${{ env.cf_preview }}${{ steps.cf.outputs.deployment-url != '' && steps.cf.outputs.deployment-url || 'Not available' }} | pr-number: ${{ github.event.pull_request.number }} comment-tag: CFPages-deployment reactions: rocket From 88f301b88393c4c0e8a90d48af83a4e38107993e Mon Sep 17 00:00:00 2001 From: hazzuk Date: Sun, 8 Dec 2024 11:44:56 +0000 Subject: [PATCH 10/11] chore(github): add comments to workflow --- .github/workflows/build.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 33b76eeb1db..6b7b5e698c4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -74,14 +74,18 @@ jobs: with: name: webapp path: . - + - name: Extract tarball run: tar -xvzf elecord.tar.gz - name: Move to dist run: mv elecord-*/ dist - # Set the Cloudflare pages branch + # Set the Cloudflare pages branch name + # - PR to master : test + # - Push to master : dev + # - PR to release : preview + # - Push to release : main (Production environment) - name: Set Pages branch run: | if [[ "${{ github.event_name }}" == "pull_request" ]]; then @@ -98,7 +102,7 @@ jobs: fi fi - # Deploy to Cloudflare using wrangler + # Deploy to Cloudflare Pages (using wrangler) - name: Deploy to Cloudflare Pages id: cf uses: cloudflare/wrangler-action@v3 @@ -124,6 +128,7 @@ jobs: reactions: -1 mode: recreate + # When deploying to the preview branch, add the preview URL - name: Add preview URL run: | if [[ "${{ env.cf_branch }}" == "preview" ]]; then From 436e0aa8b961c09f22392c58fe87881148372e37 Mon Sep 17 00:00:00 2001 From: hazzuk Date: Sun, 8 Dec 2024 11:54:09 +0000 Subject: [PATCH 11/11] chore(github): remove element deploy workflow --- .github/workflows/deploy.yml | 91 ------------------------------------ 1 file changed, 91 deletions(-) delete mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index ac6249d654a..00000000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,91 +0,0 @@ -# Manual deploy workflow for deploying to app.element.io & staging.element.io -# Runs automatically for staging.element.io when an RC or Release is published -# Note: Does *NOT* run automatically for app.element.io so that it gets tested on staging.element.io beforehand -name: Deploy release -run-name: Deploy ${{ github.ref_name }} to ${{ inputs.site || 'staging.element.io' }} -on: - release: - types: [published] - workflow_dispatch: - inputs: - site: - description: Which site to deploy to - required: true - default: staging.element.io - type: choice - options: - - staging.element.io - - app.element.io -concurrency: ${{ inputs.site || 'staging.element.io' }} -permissions: {} -jobs: - deploy: - name: "Deploy to Cloudflare Pages" - runs-on: ubuntu-24.04 - environment: ${{ inputs.site || 'staging.element.io' }} - permissions: - checks: read - deployments: write - env: - SITE: ${{ inputs.site || 'staging.element.io' }} - steps: - - uses: actions/checkout@v4 - - - name: Load GPG key - run: | - curl https://packages.element.io/element-release-key.gpg | gpg --import - gpg -k "$GPG_FINGERPRINT" - env: - GPG_FINGERPRINT: ${{ vars.GPG_FINGERPRINT }} - - - name: Check current version on deployment - id: current_version - run: | - echo "version=v$(curl -s https://$SITE/version)" >> $GITHUB_OUTPUT - - # The current version bundle melding dance is skipped if the version we're deploying is the same - # as then we're just doing a re-deploy of the same version with potentially different configs. - - name: Download current version for its old bundles - id: current_download - if: steps.current_version.outputs.version != github.ref_name - uses: ./.github/actions/download-verify-element-tarball - with: - tag: ${{ steps.current_version.outputs.version }} - out-file-path: _current_version - - - name: Download target version - uses: ./.github/actions/download-verify-element-tarball - with: - tag: ${{ github.ref_name }} - out-file-path: _deploy - - - name: Merge current bundles into target - if: steps.current_download.outcome == 'success' - run: cp -vnpr _current_version/bundles/* _deploy/bundles/ - - - name: Copy config - run: cp element.io/app/config.json _deploy/config.json - - - name: Populate 404.html - run: echo "404 Not Found" > _deploy/404.html - - - name: Populate _headers - run: cp .github/cfp_headers _deploy/_headers - - - name: Wait for other steps to succeed - uses: t3chguy/wait-on-check-action@18541021811b56544d90e0f073401c2b99e249d6 # fork - with: - ref: ${{ github.sha }} - running-workflow-name: "Deploy to Cloudflare Pages" - repo-token: ${{ secrets.GITHUB_TOKEN }} - wait-interval: 10 - check-regexp: ^((?!SonarCloud|SonarQube|issue|board|label|Release|prepare|GitHub Pages).)*$ - - - name: Deploy to Cloudflare Pages - uses: cloudflare/pages-action@f0a1cd58cd66095dee69bfa18fa5efd1dde93bca # v1 - with: - apiToken: ${{ secrets.CF_PAGES_TOKEN }} - accountId: ${{ secrets.CF_PAGES_ACCOUNT_ID }} - projectName: ${{ env.SITE == 'staging.element.io' && 'element-web-staging' || 'element-web' }} - directory: _deploy - gitHubToken: ${{ secrets.GITHUB_TOKEN }}