|
1 | 1 | # See reference docs at
|
2 | 2 | # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
|
| 3 | + |
3 | 4 | name: Pull request CI
|
4 | 5 | on: pull_request
|
5 | 6 |
|
6 | 7 | jobs:
|
7 |
| - pr-ci: |
| 8 | + pr-head-ci: |
| 9 | + runs-on: ubuntu-22.04 |
| 10 | + steps: |
| 11 | + - name: Clone the repo |
| 12 | + uses: actions/checkout@v4 |
| 13 | + with: |
| 14 | + submodules: recursive |
| 15 | + |
| 16 | + - name: Pull container image |
| 17 | + run: ./.ci/run-container-ci pull |
| 18 | + |
| 19 | + - name: Run CI in container |
| 20 | + run: ./.ci/run-container-ci ${{github.workspace}} ${{ github.base_ref }} |
| 21 | + |
| 22 | + # Generate a list of commits to run CI on |
| 23 | + generate-matrix: |
| 24 | + runs-on: ubuntu-22.04 |
| 25 | + outputs: |
| 26 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 27 | + steps: |
| 28 | + - name: Clone the repo |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + # HEAD~ because we want to skip the last commit (which is built in job above) |
| 34 | + - name: Create jobs for commits in PR history |
| 35 | + id: set-matrix |
| 36 | + run: | |
| 37 | + echo matrix=$(.ci/matrix-from-commit-log origin/${{github.base_ref}}..${{ github.event.pull_request.head.sha}}~) >> $GITHUB_OUTPUT |
| 38 | +
|
| 39 | + # Run this job for every commit in the PR except HEAD. |
| 40 | + pr-commit-ci: |
8 | 41 | runs-on: ubuntu-22.04
|
| 42 | + needs: [ generate-matrix ] |
| 43 | + strategy: |
| 44 | + matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }} |
| 45 | + if: needs.generate-matrix.outputs.matrix != '' |
9 | 46 | steps:
|
10 | 47 | - name: Clone the repo
|
11 | 48 | uses: actions/checkout@v4
|
12 | 49 | with:
|
13 | 50 | submodules: recursive
|
14 | 51 | fetch-depth: 0
|
| 52 | + ref: ${{ github.event.pull_request.base.sha }} |
15 | 53 |
|
16 |
| - # HEAD^2~ because PR branch is second parent and we want to skip the last commit |
17 |
| - - name: Dispatch jobs for commits in PR history |
| 54 | + - name: Create merge commit |
| 55 | + env: |
| 56 | + GIT_AUTHOR_NAME: Bot |
| 57 | + GIT_AUTHOR_EMAIL: bot@bitbox.swiss |
| 58 | + GIT_COMMITTER_NAME: Bot |
| 59 | + GIT_COMMITTER_EMAIL: bot@bitbox.swiss |
18 | 60 | run: |
|
19 |
| - for commit in $(git log --format="%H" origin/${{github.base_ref}}..HEAD^2~); do |
20 |
| - echo ::notice::Dispatching job for $commit |
21 |
| - curl -L -s \ |
22 |
| - -X POST \ |
23 |
| - -H "Accept: application/vnd.github+json" \ |
24 |
| - -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
25 |
| - -H "X-GitHub-Api-Version: 2022-11-28" \ |
26 |
| - ${{ github.api_url }}/repos/${{ github.repository }}/actions/workflows/commit-ci.yml/dispatches \ |
27 |
| - -d "{\"ref\":\"${{ github.event.pull_request.head.ref }}\",\"inputs\":{\"sha\":\"$commit\",\"base_ref\":\"${{ github.base_ref}}\"}}" |
28 |
| - done |
| 61 | + git fetch origin ${{ matrix.commit }} |
| 62 | + git merge --no-ff --no-edit ${{ matrix.commit }} |
| 63 | + echo "merge commit parents:" |
| 64 | + git log -1 --format="Head %H, Parents %P" |
29 | 65 |
|
30 | 66 | - name: Pull container image
|
31 | 67 | run: ./.ci/run-container-ci pull
|
|
0 commit comments