Nickez/build container in ci #30
Workflow file for this run
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
# See reference docs at | |
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions | |
name: Pull request CI | |
on: pull_request | |
jobs: | |
pr-head-ci: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Clone the repo | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
- name: Check if container files was modified and if container version already exists | |
id: checks | |
run: | | |
./.ci/check-container-sources-modified >> "$GITHUB_OUTPUT" | |
./.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 | |
run: ./.ci/pull-container | |
- name: Run CI in container | |
run: ./.ci/run-container-ci ${{github.workspace}} ${{ github.event.pull_request.base.sha }} | |
# Generate a list of commits to run CI on | |
generate-matrix: | |
runs-on: ubuntu-22.04 | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Clone the repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# HEAD~ because we want to skip the last commit (which is built in job above) | |
- name: Create jobs for commits in PR history | |
id: set-matrix | |
run: | | |
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. | |
pr-commit-ci: | |
runs-on: ubuntu-22.04 | |
needs: [ generate-matrix ] | |
strategy: | |
matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }} | |
if: needs.generate-matrix.outputs.matrix != '' | |
steps: | |
- name: Clone the repo | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.base.sha }} | |
- name: Create merge commit | |
env: | |
GIT_AUTHOR_NAME: Bot | |
GIT_AUTHOR_EMAIL: [email protected] | |
GIT_COMMITTER_NAME: Bot | |
GIT_COMMITTER_EMAIL: [email protected] | |
run: | | |
git fetch origin ${{ matrix.commit }} | |
git merge --no-ff --no-edit ${{ matrix.commit }} | |
echo "merge commit parents:" | |
git log -1 --format="Head %H, Parents %P" | |
- name: Check if container files was modified and if container version already exists | |
id: checks | |
run: | | |
./.ci/check-container-sources-modified >> "$GITHUB_OUTPUT" | |
./.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 | |
run: ./.ci/pull-container | |
- name: Run CI in container | |
run: ./.ci/run-container-ci ${{github.workspace}} ${{ github.event.pull_request.base.sha }} |