Skip to content

Commit

Permalink
ci: use git bundles instead of patches
Browse files Browse the repository at this point in the history
Using a patch with `git am` changes the commit ID. Using a bundle allows transferring a commit from one job to the other and preserving its SHA.

See https://git-scm.com/docs/git-bundle.
  • Loading branch information
alixinne authored and vtavernier committed Nov 5, 2023
1 parent c9611e3 commit d7843ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: apply-version-patch
description: Apply a version patch contained in a release artifact
name: apply-version-bundle
description: Apply a version bundle contained in a release artifact
inputs:
new_release:
description: Was a new release created
version:
description: Git tag of the created release
patch_file:
description: Path to the patch file in the artifact
bundle_file:
description: Path to the bundle file in the artifact
artifact_name:
description: Artifact name to retrieve
runs:
Expand All @@ -18,9 +18,7 @@ runs:
if: inputs.new_release == 'true'

- run: |
git config user.name "$GIT_USER"
git config user.email "$GIT_USER_EMAIL"
git am --committer-date-is-author-date ${{ inputs.patch_file }}
git pull ${{ inputs.bundle_file }} HEAD:$(git rev-parse --abbrev-ref HEAD)
git tag ${{ inputs.version }}
shell: bash
if: inputs.new_release == 'true'
Expand Down
30 changes: 17 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
outputs:
new_release: ${{ steps.outputs.outputs.new_release }}
version: ${{ steps.outputs.outputs.version }}
patch_file: ${{ steps.outputs.outputs.patch_file }}
bundle_file: ${{ steps.outputs.outputs.bundle_file }}
artifact_name: ${{ steps.outputs.outputs.artifact_name }}
check_success: ${{ steps.outputs.outputs.check_success }}

Expand Down Expand Up @@ -66,9 +66,13 @@ jobs:
# Generate changelog
cog changelog --at ${{ steps.release.outputs.version }} -t full_hash > GITHUB_CHANGELOG.md
# Generate bundle for latest commit
bundle_file=release.bundle
git bundle create $bundle_file HEAD
echo "new_release=true" >> $GITHUB_OUTPUT
echo "version=${{ steps.release.outputs.version }}" >> $GITHUB_OUTPUT
echo "patch_file=$(git format-patch HEAD^)" >> $GITHUB_OUTPUT
echo "bundle_file=$bundle_file" >> $GITHUB_OUTPUT
echo "artifact_name=release-commit" >> $GITHUB_OUTPUT
echo "check_success=true" >> $GITHUB_OUTPUT
elif [[ "${{ steps.check.outcome }}" != "success" ]]; then
Expand All @@ -88,7 +92,7 @@ jobs:
with:
name: ${{ steps.outputs.outputs.artifact_name }}
path: |
${{ steps.outputs.outputs.patch_file }}
${{ steps.outputs.outputs.bundle_file }}
GITHUB_CHANGELOG.md
if: steps.outputs.outputs.new_release == 'true'

Expand All @@ -102,11 +106,11 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/apply-version-patch
- uses: ./.github/actions/apply-version-bundle
with:
new_release: ${{ needs.version.outputs.new_release }}
version: ${{ needs.version.outputs.version }}
patch_file: ${{ needs.version.outputs.patch_file }}
bundle_file: ${{ needs.version.outputs.bundle_file }}
artifact_name: ${{ needs.version.outputs.artifact_name }}

- uses: actions/cache@v3
Expand Down Expand Up @@ -159,11 +163,11 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/apply-version-patch
- uses: ./.github/actions/apply-version-bundle
with:
new_release: ${{ needs.version.outputs.new_release }}
version: ${{ needs.version.outputs.version }}
patch_file: ${{ needs.version.outputs.patch_file }}
bundle_file: ${{ needs.version.outputs.bundle_file }}
artifact_name: ${{ needs.version.outputs.artifact_name }}

- name: Run tests
Expand Down Expand Up @@ -196,11 +200,11 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/apply-version-patch
- uses: ./.github/actions/apply-version-bundle
with:
new_release: ${{ needs.version.outputs.new_release }}
version: ${{ needs.version.outputs.version }}
patch_file: ${{ needs.version.outputs.patch_file }}
bundle_file: ${{ needs.version.outputs.bundle_file }}
artifact_name: ${{ needs.version.outputs.artifact_name }}

- name: Build windows wheels
Expand Down Expand Up @@ -250,11 +254,11 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/apply-version-patch
- uses: ./.github/actions/apply-version-bundle
with:
new_release: ${{ needs.version.outputs.new_release }}
version: ${{ needs.version.outputs.version }}
patch_file: ${{ needs.version.outputs.patch_file }}
bundle_file: ${{ needs.version.outputs.bundle_file }}
artifact_name: ${{ needs.version.outputs.artifact_name }}

- name: Build CLI binary
Expand Down Expand Up @@ -303,11 +307,11 @@ jobs:
with:
token: ${{ secrets.GH_PAT }}

- uses: ./.github/actions/apply-version-patch
- uses: ./.github/actions/apply-version-bundle
with:
new_release: ${{ needs.version.outputs.new_release }}
version: ${{ needs.version.outputs.version }}
patch_file: ${{ needs.version.outputs.patch_file }}
bundle_file: ${{ needs.version.outputs.bundle_file }}
artifact_name: ${{ needs.version.outputs.artifact_name }}

- name: Download build artifacts (x86_64-unknown-linux-gnu)
Expand Down

0 comments on commit d7843ba

Please sign in to comment.