Skip to content

Commit

Permalink
⚙️ config(ci): Factor out custom github/event action.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed May 22, 2024
1 parent 161e929 commit 64ed0d8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 70 deletions.
54 changes: 54 additions & 0 deletions .github/actions/github/event/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: github/event
description: >
Fetch generic info about GitHub event.
outputs:

merge-base:
description: >
The merge base for this event.
value: ${{ steps.merge-base.outputs.sha }}

runs:

using: composite

steps:

- name: Compute BASE_SHA and HEAD_SHA for push event 📜
if: github.event_name == 'push'
shell: bash
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'
shell: bash
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'
shell: bash
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: merge-base
env:
BASE_SHA: ${{ env.BASE_SHA }}
HEAD_SHA: ${{ env.HEAD_SHA }}
shell: bash
run: |
FIRST_NEW_COMMIT="$(git log "${BASE_SHA}..${HEAD_SHA}" --pretty=format:%H | tail -1)"
MERGE_BASE="$(git rev-parse "${FIRST_NEW_COMMIT}~")"
echo "sha=${MERGE_BASE}" >> "${GITHUB_OUTPUT}"
39 changes: 4 additions & 35 deletions .github/workflows/ci:commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,14 @@ jobs:
# 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: Compute BASE_SHA, HEAD_SHA, and MERGE_BASE 📜
id: event
uses: .github/actions/github/event

Check failure on line 34 in .github/workflows/ci:commit.yml

View workflow job for this annotation

GitHub Actions / Continuous integration (lint workflows)

specifying action ".github/actions/github/event" in invalid format because ref is missing. available formats are "{owner}/{repo}@{ref}" or "{owner}/{repo}/{path}@{ref}"

- name: Stage MERGE_BASE...HEAD_SHA ⏮️
env:
HEAD_SHA: ${{ env.HEAD_SHA }}
MERGE_BASE: ${{ steps.history.outputs.merge-base }}
MERGE_BASE: ${{ steps.event.outputs.merge-base }}
run: |
git reset --hard "${HEAD_SHA}"
git reset --soft "${MERGE_BASE}"
Expand Down
39 changes: 4 additions & 35 deletions .github/workflows/ci:precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,14 @@ jobs:
# 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: Compute BASE_SHA, HEAD_SHA, and MERGE_BASE 📜
id: event
uses: .github/actions/github/event

Check failure on line 34 in .github/workflows/ci:precommit.yml

View workflow job for this annotation

GitHub Actions / Continuous integration (lint workflows)

specifying action ".github/actions/github/event" in invalid format because ref is missing. available formats are "{owner}/{repo}@{ref}" or "{owner}/{repo}/{path}@{ref}"

- name: Stage MERGE_BASE...HEAD_SHA ⏮️
env:
HEAD_SHA: ${{ env.HEAD_SHA }}
MERGE_BASE: ${{ steps.history.outputs.merge-base }}
MERGE_BASE: ${{ steps.event.outputs.merge-base }}
run: |
git reset --hard "${HEAD_SHA}"
git reset --soft "${MERGE_BASE}"
Expand Down

0 comments on commit 64ed0d8

Please sign in to comment.