From 7be096cee7ae86ba627cb5701f398915363aa7d3 Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Tue, 18 Jul 2023 15:08:10 +0800 Subject: [PATCH] ci(PR): introduce new workflow PR --- .github/workflows/CI.yaml | 6 ++--- .github/workflows/PR.yml | 50 ++++++++++++++++++++++++++++++++++++ .github/workflows/build.yml | 13 +++++++--- .github/workflows/check.yml | 6 ++++- .github/workflows/labels.yml | 26 +++++++++++++++++++ 5 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/PR.yml create mode 100644 .github/workflows/labels.yml diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 8876ba348e4..763d364e722 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -5,10 +5,6 @@ on: - cron: "0 3 * * *" push: branches: [master, vara-stage-1, vara-stage-2, vara-stage-3] - pull_request: - branches: [master, vara-stage-1, vara-stage-2, vara-stage-3] - types: [labeled, synchronize] - workflow_dispatch: env: @@ -44,6 +40,8 @@ jobs: build: uses: ./.github/workflows/build.yml + with: + macos: true build-win-native: if: ${{ github.ref == 'refs/heads/master' }} diff --git a/.github/workflows/PR.yml b/.github/workflows/PR.yml new file mode 100644 index 00000000000..ab0e682949e --- /dev/null +++ b/.github/workflows/PR.yml @@ -0,0 +1,50 @@ +name: PR + +on: + pull_request: + branches: [master, vara-stage-1, vara-stage-2, vara-stage-3] + +env: + CARGO_INCREMENTAL: 0 + CARGO_TERM_COLOR: always + RUST_BACKTRACE: short + TERM: xterm-256color + BINARYEN_VERSION: version_111 + +jobs: + status: + runs-on: ubuntu-latest + outputs: + cache: ${{ steps.check-commit-message.outputs.cache }} + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Check Commit Message + id: check-commit-message + run: | + MESSAGE=$(git show -s --format=%s) + CACHE=true + if [[ $MESSAGE == *"[skip-cache]"* ]]; then + CACHE=false + fi + + echo "cache: ${CACHE}" + echo "cache=${CACHE}" >> $GITHUB_OUTPUT + + check: + needs: status + uses: ./.github/workflows/check.yml + with: + cache: ${{ needs.status.outputs.cache }} + + build: + needs: status + uses: ./.github/workflows/build.yml + if: >- + contains(github.event.pull_request.labels.*.name, 'A0-pleasereview') + || contains(github.event.pull_request.labels.*.name, 'A2-mergeoncegreen') + with: + cache: ${{ needs.status.outputs.cache }} + macos: contains(github.event.pull_request.labels.*.name, 'E2-forcemacos') diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9fb4e7f7115..b3c23756ce3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,6 +2,13 @@ name: Build on: workflow_call: + inputs: + cache: + type: boolean + default: true + macos: + type: boolean + default: false env: CARGO_INCREMENTAL: 0 @@ -54,7 +61,7 @@ jobs: ./rust-covfix --version - name: "Cache: Unpack" - # if: ${{ github.event_name == 'pull_request' && !contains(needs.check-commit-message.outputs.commit-message, '[skip-cache]') }} + if: ${{ inputs.cache }} continue-on-error: true run: | tar -xf /cache/build_cargo_registry_${{ github.base_ref }}.tar -C / @@ -255,7 +262,7 @@ jobs: mv ./cargo-xwin ${CARGO_HOME:-~/.cargo}/bin/ - name: "Cache: Unpack" - # if: ${{ github.event_name == 'pull_request' && !contains(needs.check-commit-message.outputs.commit-message, '[skip-cache]') }} + if: ${{ inputs.cache }} continue-on-error: true run: | tar -xf /cache/build_win_cross_cargo_registry_${{ github.base_ref }}.tar -C / @@ -293,7 +300,7 @@ jobs: mv /tmp/*.tar /cache/ macos-x86: - if: ${{ always() && (github.ref == 'refs/heads/master' || contains(github.event.pull_request.labels.*.name, 'E2-forcemacos')) }} + if: ${{ always() && inputs.macos }} needs: linux runs-on: macos-latest env: diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 6e3738e9d5a..3c510b6e227 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -2,6 +2,10 @@ name: Check on: workflow_call: + inputs: + cache: + type: boolean + default: true env: CARGO_INCREMENTAL: 0 @@ -39,7 +43,7 @@ jobs: sudo cp binaryen-$BINARYEN_VERSION/bin/wasm-opt /usr/bin/ - name: "Cache: Unpack" - # if: ${{ github.event_name == 'pull_request' && !contains(needs.check-commit-message.outputs.commit-message, '[skip-cache]') }} + if: ${{ github.event_name == 'pull_request' && !inputs.cache }} continue-on-error: true run: | tar -xf /cache/check_cargo_registry_${{ github.base_ref }}.tar -C / diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml new file mode 100644 index 00000000000..1dd48c96ae3 --- /dev/null +++ b/.github/workflows/labels.yml @@ -0,0 +1,26 @@ +name: Labels + +on: + pull_request: + branches: [master, vara-stage-1, vara-stage-2, vara-stage-3] + types: [labeled] + +jobs: + check: + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{ github.token }} + + build: + uses: ./.github/workflows/build.yml + # TODO: dispatch this workflow with github action API + # for more conditions. for example, if the there is + # already a build check exist. (issue-2888) + if: >- + github.event.label.name == 'A0-pleasereview' + || github.event.label.name == 'E2-forcemacos' + with: + macos: github.event.label.name == 'E2-forcemacos'