|
| 1 | +# Separate to the main build workflow for access to develop |
| 2 | +# environment secrets, largely similar to build.yaml. |
| 3 | +name: Build and Deploy develop |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [develop] |
| 7 | + repository_dispatch: |
| 8 | + types: [element-web-notify] |
| 9 | +concurrency: |
| 10 | + group: ${{ github.repository_owner }}-${{ github.workflow }}-${{ github.ref_name }} |
| 11 | + cancel-in-progress: true |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: "Build & Deploy develop.element.io" |
| 15 | + # Only respect triggers from our develop branch, ignore that of forks |
| 16 | + if: github.repository == 'vector-im/element-web' |
| 17 | + runs-on: ubuntu-latest |
| 18 | + environment: develop |
| 19 | + env: |
| 20 | + R2_BUCKET: "element-web-develop" |
| 21 | + R2_URL: ${{ vars.CF_R2_S3_API }} |
| 22 | + R2_PUBLIC_URL: "https://element-web-develop.element.io" |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v3 |
| 25 | + |
| 26 | + - uses: actions/setup-node@v3 |
| 27 | + with: |
| 28 | + cache: "yarn" |
| 29 | + |
| 30 | + - name: Install Dependencies |
| 31 | + run: "./scripts/layered.sh" |
| 32 | + |
| 33 | + - name: Build, Package & Upload sourcemaps |
| 34 | + run: "./scripts/ci_package.sh" |
| 35 | + env: |
| 36 | + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} |
| 37 | + SENTRY_DSN: ${{ secrets.SENTRY_DSN }} |
| 38 | + SENTRY_URL: ${{ secrets.SENTRY_URL }} |
| 39 | + SENTRY_ORG: element |
| 40 | + SENTRY_PROJECT: riot-web |
| 41 | + # We only deploy the latest bundles to Cloudflare Pages and use _redirects to fallback to R2 for |
| 42 | + # older ones. This redirect means that 'self' is insufficient in the CSP, |
| 43 | + # and we have to add the R2 URL. |
| 44 | + # Once Cloudflare redirects support proxying mode we will be able to ditch this. |
| 45 | + # See Proxying in support table at https://developers.cloudflare.com/pages/platform/redirects |
| 46 | + CSP_EXTRA_SOURCE: ${{ env.R2_PUBLIC_URL }} |
| 47 | + |
| 48 | + - run: mv dist/element-*.tar.gz dist/develop.tar.gz |
| 49 | + |
| 50 | + - uses: actions/upload-artifact@v3 |
| 51 | + with: |
| 52 | + name: webapp |
| 53 | + path: dist/develop.tar.gz |
| 54 | + retention-days: 1 |
| 55 | + |
| 56 | + - name: Extract webapp |
| 57 | + run: | |
| 58 | + mkdir _deploy |
| 59 | + tar xf dist/develop.tar.gz -C _deploy --strip-components=1 |
| 60 | +
|
| 61 | + - name: Copy config |
| 62 | + run: cp element.io/develop/config.json _deploy/config.json |
| 63 | + |
| 64 | + - name: Populate 404.html |
| 65 | + run: echo "404 Not Found" > _deploy/404.html |
| 66 | + |
| 67 | + - name: Populate _headers |
| 68 | + run: cp .github/cfp_headers _deploy/_headers |
| 69 | + |
| 70 | + # Redirect requests for the develop tarball and the historical bundles to R2 |
| 71 | + - name: Populate _redirects |
| 72 | + run: | |
| 73 | + { |
| 74 | + echo "/develop.tar.gz $R2_PUBLIC_URL/develop.tar.gz 301" |
| 75 | + for bundle in $(aws s3 ls s3://$R2_BUCKET/bundles/ --endpoint-url $R2_URL --region=auto | awk '{print $2}'); do |
| 76 | + echo "/bundles/${bundle}* $R2_PUBLIC_URL/bundles/${bundle}:splat 301" |
| 77 | + done |
| 78 | + } | tee _deploy/_redirects |
| 79 | + env: |
| 80 | + AWS_ACCESS_KEY_ID: ${{ secrets.CF_R2_ACCESS_KEY_ID }} |
| 81 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_TOKEN }} |
| 82 | + |
| 83 | + - name: Wait for other steps to succeed |
| 84 | + uses: t3chguy/wait-on-check-action@05861d3a448898eb33dfce34153bd1ecb9422fb9 # fork |
| 85 | + with: |
| 86 | + ref: ${{ github.sha }} |
| 87 | + running-workflow-name: "Build & Deploy develop.element.io" |
| 88 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + wait-interval: 10 |
| 90 | + check-regexp: ^((?!SonarCloud|SonarQube|issue|board|label).)*$ |
| 91 | + |
| 92 | + # We keep the latest develop.tar.gz on R2 instead of relying on the github artifact uploaded earlier |
| 93 | + # as the expires after 24h and requires auth to download. |
| 94 | + # Element Desktop's fetch script uses this tarball to fetch latest develop to build Nightlies. |
| 95 | + - name: Deploy to R2 |
| 96 | + run: | |
| 97 | + aws s3 cp dist/develop.tar.gz s3://$R2_BUCKET/develop.tar.gz --endpoint-url $R2_URL --region=auto |
| 98 | + aws s3 cp _deploy/ s3://$R2_BUCKET/ --recursive --endpoint-url $R2_URL --region=auto |
| 99 | + env: |
| 100 | + AWS_ACCESS_KEY_ID: ${{ secrets.CF_R2_ACCESS_KEY_ID }} |
| 101 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_TOKEN }} |
| 102 | + |
| 103 | + - name: Deploy to Cloudflare Pages |
| 104 | + id: cfp |
| 105 | + uses: cloudflare/pages-action@61eafe73baad0195ab582cb447b2c6e15a0df9ce # v1 |
| 106 | + with: |
| 107 | + apiToken: ${{ secrets.CF_PAGES_TOKEN }} |
| 108 | + accountId: ${{ secrets.CF_PAGES_ACCOUNT_ID }} |
| 109 | + projectName: element-web-develop |
| 110 | + directory: _deploy |
| 111 | + gitHubToken: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + |
| 113 | + - run: | |
| 114 | + echo "Deployed to ${{ steps.cfp.outputs.url }}" >> $GITHUB_STEP_SUMMARY |
0 commit comments