element-web/.github/workflows/build.yaml
2022-04-27 13:10:39 +01:00

107 lines
3.2 KiB
YAML

name: Build
on:
pull_request: { }
push:
branches: [ master, develop ]
repository_dispatch:
types: [ element-web-notify ]
jobs:
build:
name: "Build"
runs-on: ubuntu-latest
env:
# This must be set for fetchdep.sh to get the right branch
PR_NUMBER: ${{github.event.number}}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
cache: 'yarn'
- name: Install SDKs
run: "./scripts/fetch-develop.deps.sh --depth 1"
- name: Install Dependencies
run: "yarn install"
- name: Build & Package
run: "./scripts/ci_package.sh"
- name: Upload webpack-stats.json
uses: actions/upload-artifact@v2
with:
path: webpack-stats.json
retention-days: 28
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: previewbuild
path: dist/*.tar.gz
retention-days: ${{ github.ref == 'develop' && 1 || 28 }}
deploy:
name: "Deploy to develop.element.io"
needs: build
runs-on: ubuntu-latest
# if: github.event_name == 'push' && github.ref == 'develop'
steps:
- name: Find Artifact ID
uses: actions/github-script@v3.1.0
id: find_artifact
with:
result-encoding: string
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.run_id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "previewbuild"
})[0];
return matchArtifact.id;
- name: Create Deployment
uses: avakar/create-deployment@v1
id: deployment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
environment: Develop
initial_status: in_progress
ref: ${{ github.head_ref }}
transient_environment: true
auto_merge: false
task: deploy
payload: '{"artifact_id": "${{ steps.find_artifact.outputs.result }}"}'
# TODO
# - name: Invoke deployment hook
# uses: distributhor/workflow-webhook@v2
# env:
# webhook_url: https://test.tun.bit.ovh
# webhook_secret: FooBar
# data: '{ "artifact_id": "${{steps.find_artifact.outputs.result}}" }'
- name: Update deployment status (success)
if: success()
uses: avakar/set-deployment-status@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
environment: Develop
environment_url: https://develop.element.io
state: "success"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
auto_inactive: true
- name: Update deployment status (failure)
if: failure()
uses: altinukshini/deployment-status@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
state: "failure"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
environment: Develop