Skip to content

Commit 51bc17b

Browse files
committed
Factor out duplicated code
1 parent 6d22820 commit 51bc17b

File tree

2 files changed

+47
-42
lines changed

2 files changed

+47
-42
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Pull request CI common
2+
3+
inputs:
4+
base-sha:
5+
required: true
6+
runs:
7+
using: "composite"
8+
steps:
9+
- name: Check if container files was modified and if container version already exists
10+
id: checks
11+
shell: bash
12+
run: |
13+
echo modified=$(./.ci/check-container-sources-modified) >> "$GITHUB_OUTPUT"
14+
echo container-published=$(./.ci/check-container-version-published) >> "$GITHUB_OUTPUT"
15+
16+
- name: Build container image
17+
if: steps.checks.outputs.modified == 'true'
18+
shell: bash
19+
run: |
20+
if "${{ steps.checks.outputs.container-published }}" == "true"; then
21+
echo "::error::Container modified but version $(cat .containerversion) already published"
22+
exit 1
23+
fi
24+
./.ci/build-container
25+
26+
- name: Pull container image
27+
if: steps.checks.outputs.modified == 'false'
28+
shell: bash
29+
run: ./.ci/pull-container
30+
31+
- name: Run CI in container
32+
shell: bash
33+
run: ./.ci/run-container-ci ${{github.workspace}} ${{ inputs.base-sha }}

.github/workflows/pr-ci.yml

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,10 @@ jobs:
1414
submodules: recursive
1515
fetch-depth: 0
1616

17-
- name: Check if container files was modified and if container version already exists
18-
id: checks
19-
run: |
20-
echo modified=$(./.ci/check-container-sources-modified) >> "$GITHUB_OUTPUT"
21-
echo container-published=$(./.ci/check-container-version-published) >> "$GITHUB_OUTPUT"
22-
23-
- name: Build container image
24-
if: steps.checks.outputs.modified == 'true'
25-
run: |
26-
if "${{ steps.checks.outputs.container-published }}" == "true"; then
27-
echo "::error::Container modified but version $(cat .containerversion) already published"
28-
exit 1
29-
fi
30-
./.ci/build-container
31-
32-
- name: Pull container image
33-
if: steps.checks.outputs.modified == 'false'
34-
run: ./.ci/pull-container
35-
36-
- name: Run CI in container
37-
run: ./.ci/run-container-ci ${{github.workspace}} ${{ github.event.pull_request.base.sha }}
17+
- name: CI
18+
uses: ./.github/actions/pr-ci-common
19+
with:
20+
base-sha: ${{ github.event.pull_request.base.sha }}
3821

3922
# Generate a list of commits to run CI on
4023
generate-matrix:
@@ -54,6 +37,12 @@ jobs:
5437
echo matrix=$(.ci/matrix-from-commit-log ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}~) >> $GITHUB_OUTPUT
5538
5639
# Run this job for every commit in the PR except HEAD.
40+
# This job simulates what github does for the PR HEAD commit but for every other commit in the
41+
# PR. So for every commit, it creates a merge commit between that commit and the base branch.
42+
# Then it runs the CI on that merge commit.
43+
# The only caveat is that this file (pr-ci.yml) is already loaded from the PR HEAD merge commit,
44+
# and therefore we need to load the `.ci` scripts from the PR HEAD merge commit. The outcome of
45+
# that is that changes to the CI is not tested per commit. All commits use the final version.
5746
pr-commit-ci:
5847
runs-on: ubuntu-22.04
5948
needs: [ generate-matrix ]
@@ -82,24 +71,7 @@ jobs:
8271
# get the .ci scripts from there as well.
8372
git checkout -f ${{ github.event.pull_request.merge_commit_sha }} -- .ci .github
8473
85-
- name: Check if container files was modified and if container version already exists
86-
id: checks
87-
run: |
88-
echo modified=$(./.ci/check-container-sources-modified) >> "$GITHUB_OUTPUT"
89-
echo container-published=$(./.ci/check-container-version-published) >> "$GITHUB_OUTPUT"
90-
91-
- name: Build container image
92-
if: steps.checks.outputs.modified == 'true'
93-
run: |
94-
if "${{ steps.checks.outputs.container-published }}" == "true"; then
95-
echo "::error::Container modified but version $(cat .containerversion) already published"
96-
exit 1
97-
fi
98-
./.ci/build-container
99-
100-
- name: Pull container image
101-
if: steps.checks.outputs.modified == 'false'
102-
run: ./.ci/pull-container
103-
104-
- name: Run CI in container
105-
run: ./.ci/run-container-ci ${{github.workspace}} ${{ github.event.pull_request.base.sha }}
74+
- name: CI
75+
uses: ./.github/actions/pr-ci-common
76+
with:
77+
base-sha: ${{ github.event.pull_request.base.sha }}

0 commit comments

Comments
 (0)