Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Fix per commit CI #1277

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .ci/matrix-from-commit-log
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/python

import subprocess
import sys
import json

range = sys.argv[1]

commits = subprocess.run(f'git log --format="%H" {range}', shell=True, text=True, capture_output=True)
commits = commits.stdout.strip().split()

if len(commits) > 0:
print(json.dumps({'commit': commits}))
61 changes: 0 additions & 61 deletions .github/workflows/commit-ci.yml

This file was deleted.

62 changes: 49 additions & 13 deletions .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,67 @@
# 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-ci:
pr-head-ci:
runs-on: ubuntu-22.04
steps:
- name: Clone the repo
uses: actions/checkout@v4
with:
submodules: recursive

- name: Pull container image
run: ./.ci/run-container-ci pull

- name: Run CI in container
run: ./.ci/run-container-ci ${{github.workspace}} ${{ github.base_ref }}

# 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 origin/${{github.base_ref}}..${{ 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 }}

# HEAD^2~ because PR branch is second parent and we want to skip the last commit
- name: Dispatch jobs for commits in PR history
- name: Create merge commit
env:
GIT_AUTHOR_NAME: Bot
GIT_AUTHOR_EMAIL: [email protected]
GIT_COMMITTER_NAME: Bot
GIT_COMMITTER_EMAIL: [email protected]
run: |
for commit in $(git log --format="%H" origin/${{github.base_ref}}..HEAD^2~); do
echo ::notice::Dispatching job for $commit
curl -L -s \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${{ github.api_url }}/repos/${{ github.repository }}/actions/workflows/commit-ci.yml/dispatches \
-d "{\"ref\":\"${{ github.event.pull_request.head.ref }}\",\"inputs\":{\"sha\":\"$commit\",\"base_ref\":\"${{ github.base_ref}}\"}}"
done
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: Pull container image
run: ./.ci/run-container-ci pull
Expand Down