diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b2bcb1fb83a..6b7b5e698c4 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 @@ -59,4 +59,94 @@ 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 + permissions: + pull-requests: write + steps: + # Download and extract the build folder + - name: Download Artifact + uses: actions/download-artifact@v4 + 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 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 + 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 Pages (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 --branch=${{ env.cf_branch }} + + # Update PR status comment with deployment URL + - name: Update status comment (Failure) + if: ${{ github.event_name == 'pull_request' && failure() }} + uses: thollander/actions-comment-pull-request@v3 + with: + 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 | + pr-number: ${{ github.event.pull_request.number }} + comment-tag: CFPages-deployment + 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 + 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 + with: + message: | + ## Cloudflare Pages deployment + + | **Latest commit** | ${{ github.event.pull_request.head.sha || github.sha }} | + |-------------------|:-:| + | **Status** | ✅ Deployed! | + | **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 + mode: recreate \ No newline at end of file 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 }}