-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
โ๏ธ config(ci): Add workflow to test all commit hooks.
Fixes #795.
- Loading branch information
1 parent
d645a5d
commit 161e929
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
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-parse "${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: Configure git ๐ช | ||
env: | ||
SENDER_ID: ${{ github.event.sender.id }} | ||
SENDER_USERNAME: ${{ github.event.sender.login }} | ||
run: | | ||
git config --global user.email "${SENDER_ID}+${SENDER_USERNAME}@users.noreply.github.com" | ||
git config --global user.name "${SENDER_USERNAME}" | ||
- name: Run commit hooks ๐ฌ | ||
env: | ||
HEAD_SHA: ${{ env.HEAD_SHA }} | ||
MERGE_BASE: ${{ steps.history.outputs.merge-base }} | ||
run: | | ||
MERGE_BASE_SHORT="$(git rev-parse --short "${MERGE_BASE}")" | ||
HEAD_SHA_SHORT="$(git rev-parse --short "${HEAD_SHA}")" | ||
git commit -m ":construction: progress: Check commit hooks for ${MERGE_BASE_SHORT}...${HEAD_SHA_SHORT}." |