From fc2a081f250e86bb35a8f3e72f19bde463e8d470 Mon Sep 17 00:00:00 2001 From: make-github-pseudonymous-again <5165674+make-github-pseudonymous-again@users.noreply.github.com> Date: Wed, 22 May 2024 11:48:23 +0200 Subject: [PATCH] :gear: config(ci): Add workflow to test all commit hooks. Fixes #795. --- .github/workflows/ci:commit.yml | 87 +++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/workflows/ci:commit.yml diff --git a/.github/workflows/ci:commit.yml b/.github/workflows/ci:commit.yml new file mode 100644 index 000000000..5e854adb3 --- /dev/null +++ b/.github/workflows/ci:commit.yml @@ -0,0 +1,87 @@ +name: ci:commit + +on: + push: + branches: + - main + pull_request: + merge_group: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + + test: + name: Continuous integration (test commit) + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v4 + with: + # TODO Fetch sparingly with something similar to + # https://github.com/rmacklin/fetch-through-merge-base/blob/main/action.yml + # Maybe could use commit count (does not exist on merge_group + # somehow) + # Maybe setting .git/shallow to base first would work in all cases? + # See https://stackoverflow.com/a/76573878 + fetch-depth: 0 + + # TODO Make this a reusable action + - name: Compute BASE_SHA and HEAD_SHA for push event 📜 + if: github.event_name == 'push' + run: | + BASE_SHA="${{ github.event.before }}" + echo "BASE_SHA=${BASE_SHA}" >> "${GITHUB_ENV}" + HEAD_SHA="${{ github.event.after }}" + echo "HEAD_SHA=${HEAD_SHA}" >> "${GITHUB_ENV}" + + - name: Compute BASE_SHA and HEAD_SHA for pull_request event 📜 + if: github.event_name == 'pull_request' + run: | + BASE_SHA="${{ github.event.pull_request.base.sha }}" + echo "BASE_SHA=${BASE_SHA}" >> "${GITHUB_ENV}" + HEAD_SHA="${{ github.event.pull_request.head.sha }}" + echo "HEAD_SHA=${HEAD_SHA}" >> "${GITHUB_ENV}" + + - name: Compute BASE_SHA and HEAD_SHA for merge_group event 📜 + if: github.event_name == 'merge_group' + run: | + BASE_SHA="${{ github.event.merge_group.base_sha }}" + echo "BASE_SHA=${BASE_SHA}" >> "${GITHUB_ENV}" + HEAD_SHA="${{ github.event.merge_group.head_sha }}" + echo "HEAD_SHA=${HEAD_SHA}" >> "${GITHUB_ENV}" + + - name: Compute MERGE_BASE 🌱 + id: history + env: + BASE_SHA: ${{ env.BASE_SHA }} + HEAD_SHA: ${{ env.HEAD_SHA }} + run: | + FIRST_NEW_COMMIT="$(git log "${BASE_SHA}..${HEAD_SHA}" --pretty=format:%H | tail -1)" + MERGE_BASE="$(git rev-list -n1 "${FIRST_NEW_COMMIT}~")" + echo "merge-base=${MERGE_BASE}" >> "${GITHUB_OUTPUT}" + + - name: Stage MERGE_BASE...HEAD_SHA ⏮️ + env: + HEAD_SHA: ${{ env.HEAD_SHA }} + MERGE_BASE: ${{ steps.history.outputs.merge-base }} + run: | + git reset --hard "${HEAD_SHA}" + git reset --soft "${MERGE_BASE}" + + - name: Install 💾 + uses: ./.github/actions/install + + - name: Install commit hooks 🪝 + run: | + meteor npm run install-hooks + + - name: Run commit hooks 🔬 + env: + HEAD_SHA: ${{ env.HEAD_SHA }} + MERGE_BASE: ${{ steps.history.outputs.merge-base }} + run: | + git commit -m ':construction: progress: Check commit hooks for ${MERGE_BASE}...${HEAD_SHA}.'