From 3bc70948746e7ec2da61afc98abf7501d84f141b Mon Sep 17 00:00:00 2001 From: Stefan Matting Date: Mon, 22 Jan 2024 14:24:33 +0100 Subject: [PATCH] refactor: branch vs pr pipelines --- .github/workflows/ci.yml | 90 +++++++++++++++++++++++++ .github/workflows/lint.yml | 29 -------- .github/workflows/test_build_deploy.yml | 16 +---- 3 files changed, 92 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..e023d31660 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,90 @@ +name: CI + +on: + push: + branches: [staging, main] + tags: + - v* + pull_request: + branches: [staging, main] + + +jobs: + test_build_deploy: + runs-on: ubuntu-latest + + strategy: + matrix: + DISTRIBUTION: ['DISTRIBUTION_0'] + + env: + TEST_COVERAGE_FAIL_THRESHOLD: 10 + TEST_COVERAGE_WARNING_THRESHOLD: 50 + DEPLOYMENT_RECOVERY_TIMEOUT_SECONDS: 150 + AWS_APPLICATION_NAME: Account + AWS_BUILD_ZIP_PATH: 'wire-account.zip' + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set environment variables + env: + # DISTRIBUTIONS are saved in the format `distribution-{name}` + DISTRIBUTION: ${{secrets[matrix.DISTRIBUTION]}} + run: | + echo "BRANCH_NAME=$(git branch --show-current)" >> $GITHUB_ENV + echo "TAG=$(git tag --points-at ${{github.sha}})" >> $GITHUB_ENV + echo "COMMIT_MESSAGE=$(git log --format=%B -n 1 ${{github.event.after}} | head -n 1)" >> $GITHUB_ENV + echo "DISTRIBUTION=${DISTRIBUTION/distribution-/}" >> $GITHUB_ENV + + - name: Set TITLE + env: + PR_TITLE: ${{github.event.pull_request.title || env.COMMIT_MESSAGE}} + run: echo "TITLE=$PR_TITLE" >> $GITHUB_ENV + + - name: Print environment variables + env: + GITHUB_CONTEXT: ${{toJson(github)}} + run: | + echo -e "BRANCH_NAME = ${BRANCH_NAME}" + echo -e "TAG = ${TAG}" + echo -e "TITLE = ${TITLE}" + echo -e "COMMIT_MESSAGE = ${COMMIT_MESSAGE}" + echo -e "GITHUB_CONTEXT = ${GITHUB_CONTEXT}" + + - name: Skip CI + if: contains(env.TITLE || env.COMMIT_MESSAGE, '[skip ci]') || contains(env.TITLE || env.COMMIT_MESSAGE, '[ci skip]') + uses: andymckay/cancel-action@0.3 + + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{github.token}} + + - name: Yarn cache + uses: c-hive/gha-yarn-cache@v2.1.0 + + - name: Authenticate git clone + env: + GH_TOKEN: ${{secrets.OTTO_THE_BOT_GH_TOKEN}} + run: echo -e "machine github.com\n login ${GH_TOKEN}" > ~/.netrc + + - name: Install JS dependencies + run: yarn --immutable + + - name: Lint + run: yarn lint + + - name: Test + if: matrix.DISTRIBUTION == 'DISTRIBUTION_0' + run: yarn test + + - name: Monitor coverage + if: github.event_name == 'pull_request' && matrix.DISTRIBUTION == 'DISTRIBUTION_0' + uses: slavcodev/coverage-monitor-action@1.8.0 + with: + github_token: ${{github.token}} + clover_file: 'coverage/clover.xml' + threshold_alert: ${{env.TEST_COVERAGE_FAIL_THRESHOLD}} + threshold_warning: ${{env.TEST_COVERAGE_WARNING_THRESHOLD}} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index f2e76dcfda..0000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Lint - -on: - push: - branches: [staging, main] - pull_request: - branches: [staging, main] - -jobs: - lint: - runs-on: ubuntu-latest - - steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.11.0 - with: - access_token: ${{github.token}} - - - name: Checkout - uses: actions/checkout@v3 - - - name: Yarn cache - uses: c-hive/gha-yarn-cache@v2 - - - name: Install JS dependencies - run: yarn --frozen-lockfile - - - name: Lint - run: yarn lint diff --git a/.github/workflows/test_build_deploy.yml b/.github/workflows/test_build_deploy.yml index 3b56900456..3b2dc23d86 100644 --- a/.github/workflows/test_build_deploy.yml +++ b/.github/workflows/test_build_deploy.yml @@ -2,11 +2,10 @@ name: Test, Build & Deploy on: push: - branches: [staging, main] + # TODO: remove before merging PR + branches: [staging, main, WPB-6025-refactor] tags: - v* - pull_request: - branches: [staging, main] jobs: test_build_deploy: @@ -17,8 +16,6 @@ jobs: DISTRIBUTION: ['DISTRIBUTION_0'] env: - TEST_COVERAGE_FAIL_THRESHOLD: 10 - TEST_COVERAGE_WARNING_THRESHOLD: 50 DEPLOYMENT_RECOVERY_TIMEOUT_SECONDS: 150 AWS_APPLICATION_NAME: Account AWS_BUILD_ZIP_PATH: 'wire-account.zip' @@ -76,15 +73,6 @@ jobs: if: matrix.DISTRIBUTION == 'DISTRIBUTION_0' run: yarn test - - name: Monitor coverage - if: github.event_name == 'pull_request' && matrix.DISTRIBUTION == 'DISTRIBUTION_0' - uses: slavcodev/coverage-monitor-action@1.8.0 - with: - github_token: ${{github.token}} - clover_file: 'coverage/clover.xml' - threshold_alert: ${{env.TEST_COVERAGE_FAIL_THRESHOLD}} - threshold_warning: ${{env.TEST_COVERAGE_WARNING_THRESHOLD}} - - name: Create commit file run: | mkdir -p ./dist