Skip to content

Commit

Permalink
Factor out duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
NickeZ committed Aug 22, 2024
1 parent 6d22820 commit 51bc17b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 42 deletions.
33 changes: 33 additions & 0 deletions .github/actions/pr-ci-common/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Pull request CI common

inputs:
base-sha:
required: true
runs:
using: "composite"
steps:
- name: Check if container files was modified and if container version already exists
id: checks
shell: bash
run: |
echo modified=$(./.ci/check-container-sources-modified) >> "$GITHUB_OUTPUT"
echo container-published=$(./.ci/check-container-version-published) >> "$GITHUB_OUTPUT"
- name: Build container image
if: steps.checks.outputs.modified == 'true'
shell: bash
run: |
if "${{ steps.checks.outputs.container-published }}" == "true"; then
echo "::error::Container modified but version $(cat .containerversion) already published"
exit 1
fi
./.ci/build-container
- name: Pull container image
if: steps.checks.outputs.modified == 'false'
shell: bash
run: ./.ci/pull-container

- name: Run CI in container
shell: bash
run: ./.ci/run-container-ci ${{github.workspace}} ${{ inputs.base-sha }}
56 changes: 14 additions & 42 deletions .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,10 @@ jobs:
submodules: recursive
fetch-depth: 0

- name: Check if container files was modified and if container version already exists
id: checks
run: |
echo modified=$(./.ci/check-container-sources-modified) >> "$GITHUB_OUTPUT"
echo container-published=$(./.ci/check-container-version-published) >> "$GITHUB_OUTPUT"
- name: Build container image
if: steps.checks.outputs.modified == 'true'
run: |
if "${{ steps.checks.outputs.container-published }}" == "true"; then
echo "::error::Container modified but version $(cat .containerversion) already published"
exit 1
fi
./.ci/build-container
- name: Pull container image
if: steps.checks.outputs.modified == 'false'
run: ./.ci/pull-container

- name: Run CI in container
run: ./.ci/run-container-ci ${{github.workspace}} ${{ github.event.pull_request.base.sha }}
- name: CI
uses: ./.github/actions/pr-ci-common
with:
base-sha: ${{ github.event.pull_request.base.sha }}

# Generate a list of commits to run CI on
generate-matrix:
Expand All @@ -54,6 +37,12 @@ jobs:
echo matrix=$(.ci/matrix-from-commit-log ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}~) >> $GITHUB_OUTPUT
# Run this job for every commit in the PR except HEAD.
# This job simulates what github does for the PR HEAD commit but for every other commit in the
# PR. So for every commit, it creates a merge commit between that commit and the base branch.
# Then it runs the CI on that merge commit.
# The only caveat is that this file (pr-ci.yml) is already loaded from the PR HEAD merge commit,
# and therefore we need to load the `.ci` scripts from the PR HEAD merge commit. The outcome of
# that is that changes to the CI is not tested per commit. All commits use the final version.
pr-commit-ci:
runs-on: ubuntu-22.04
needs: [ generate-matrix ]
Expand Down Expand Up @@ -82,24 +71,7 @@ jobs:
# get the .ci scripts from there as well.
git checkout -f ${{ github.event.pull_request.merge_commit_sha }} -- .ci .github
- name: Check if container files was modified and if container version already exists
id: checks
run: |
echo modified=$(./.ci/check-container-sources-modified) >> "$GITHUB_OUTPUT"
echo container-published=$(./.ci/check-container-version-published) >> "$GITHUB_OUTPUT"
- name: Build container image
if: steps.checks.outputs.modified == 'true'
run: |
if "${{ steps.checks.outputs.container-published }}" == "true"; then
echo "::error::Container modified but version $(cat .containerversion) already published"
exit 1
fi
./.ci/build-container
- name: Pull container image
if: steps.checks.outputs.modified == 'false'
run: ./.ci/pull-container

- name: Run CI in container
run: ./.ci/run-container-ci ${{github.workspace}} ${{ github.event.pull_request.base.sha }}
- name: CI
uses: ./.github/actions/pr-ci-common
with:
base-sha: ${{ github.event.pull_request.base.sha }}

0 comments on commit 51bc17b

Please sign in to comment.