Skip to content

Commit

Permalink
Merge pull request #8731 from Agoric/mfig-ci-external-prs
Browse files Browse the repository at this point in the history
ci: allow externally forked PRs to pass CI
  • Loading branch information
michaelfig authored and mhofman committed Jan 12, 2024
2 parents 14120e2 + 28e5380 commit 6d81783
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 76 deletions.
56 changes: 5 additions & 51 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ jobs:
- uses: actions/checkout@v3
with:
persist-credentials: false
- name: Recreate integration-test-result if needed
id: get-pending-integration-result
uses: ./.github/actions/get-latest-check
with:
create-if-needed: true
- name: Reconfigure git to use HTTP authentication
run: git config --global url."https://github.com/".insteadOf ssh://git@github.com/
shell: bash
Expand Down Expand Up @@ -117,11 +112,6 @@ jobs:
with:
submodules: 'true'
path: ./agoric-sdk
- name: Recreate integration-test-result if needed
id: get-pending-integration-result
uses: ./agoric-sdk/.github/actions/get-latest-check
with:
create-if-needed: true
- run: sudo packages/deployment/scripts/install-deps.sh
working-directory: ./agoric-sdk
- uses: ./agoric-sdk/.github/actions/restore-golang
Expand Down Expand Up @@ -237,11 +227,6 @@ jobs:
echo "=== After cleanup:"
df -h
- uses: actions/checkout@v3
- name: Recreate integration-test-result if needed
id: get-pending-integration-result
uses: ./.github/actions/get-latest-check
with:
create-if-needed: true
- name: docker build (sdk)
# Produces ghcr.io/agoric/agoric-sdk:latest used in the following upgrade test.
# run: cd packages/deployment && ./scripts/test-docker-build.sh | $TEST_COLLECT
Expand Down Expand Up @@ -270,29 +255,6 @@ jobs:
with:
datadog-token: ${{ secrets.DATADOG_API_KEY }}

set-integration-result-in-progress:
needs: pre_check
if: needs.pre_check.outputs.should_run == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: get-pending-integration-result
uses: ./.github/actions/get-latest-check
with:
create-if-needed: true
- name: Update integration-test-result check to in-progress
uses: actions/github-script@v6
with:
script: |
const runId = "${{ steps.get-pending-integration-result.outputs.run_id }}";
const res = await github.rest.checks.update({
...context.repo,
check_run_id: runId,
status: "in_progress",
})
core.debug(`Check update response: ${JSON.stringify(res, null, 2)}`)
console.log(`Updated check ${runId} to in-progress`)
finalize-integration-result:
needs:
- pre_check
Expand All @@ -312,26 +274,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: get-pending-integration-result
uses: ./.github/actions/get-latest-check
with:
create-if-needed: true
- name: Publish integration-test-result
- name: Final integration-test-result
if: always()
uses: actions/github-script@v6
with:
script: |
const runId = "${{ steps.get-pending-integration-result.outputs.run_id }}";
const previousSuccess = ${{ needs.pre_check.outputs.previous_success }};
const gettingStartedTestSuccess = "${{ needs.getting-started.result }}" === "success";
const deploymentTestSuccess = "${{ needs.deployment-test.result }}" === "success";
const testDockerBuildSuccess = "${{ needs.test-docker-build.result }}" === "success";
const conclusion = previousSuccess || (gettingStartedTestSuccess && deploymentTestSuccess && testDockerBuildSuccess) ?
'success' : 'failure';
const res = await github.rest.checks.update({
...context.repo,
check_run_id: runId,
conclusion,
})
core.debug(`Check update response: ${JSON.stringify(res, null, 2)}`)
console.log(`Updated check ${runId} to ${conclusion}`)
console.log(`Finishing with ${conclusion}`)
if (conclusion === 'failure') {
core.setFailed('Integration tests failed')
}
84 changes: 84 additions & 0 deletions .github/workflows/manage-integration-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Manage integration check

on:
workflow_run:
workflows: ['Integration tests']

jobs:
create-check:
runs-on: ubuntu-latest
outputs:
check_id: ${{ steps.create-check.outputs.result }}
steps:
- name: Create check
uses: actions/github-script@v6
id: create-check
if: ${{ github.event.action == 'requested' || github.event.action == 'in_progress' }}
with:
script: |
const external_id = context.payload.workflow_run.html_url;
const head_sha = context.payload.workflow_run.head_sha;
const runs = await github.paginate(github.rest.checks.listForRef, {
...context.repo,
ref: head_sha,
check_name: "integration-test-result",
external_id,
})
core.debug(`integration-test-result check runs: ${JSON.stringify(runs, null, 2)}`);
const filtRuns = runs.filter(run => run.status !== 'completed');
const descRuns = filtRuns.sort((a, b) => Date.parse(b.started_at) - Date.parse(a.started_at));
const run = descRuns[0];
if (run) {
// Check already exists.
return run.id;
}
const check = await github.rest.checks.create({
...context.repo,
head_sha,
name: "integration-test-result",
status: "in_progress",
external_id,
output: {
title: "Integration Test Aggregate Result",
summary: `Synthetic check capturing the result of the <a href="${context.payload.workflow_run.html_url}">integration-test workflow run</a>`,
}
});
return check.data.id;
update-check:
runs-on: ubuntu-latest
steps:
- name: Update check result
uses: actions/github-script@v6
if: ${{ github.event.action == 'completed' }}
with:
result-encoding: string
script: |
// Update the check run
const external_id = context.payload.workflow_run.html_url;
const head_sha = context.payload.workflow_run.head_sha;
const runs = await github.paginate(github.rest.checks.listForRef, {
...context.repo,
ref: head_sha,
check_name: "integration-test-result",
external_id,
})
core.debug(`integration-test-result check runs: ${JSON.stringify(runs, null, 2)}`);
const filtRuns = runs.filter(run => run.status !== 'completed');
const descRuns = filtRuns.sort((a, b) => Date.parse(b.started_at) - Date.parse(a.started_at));
const run = descRuns[0];
if (!run) {
core.setFailed(`No integration-test-result check found for commit ${head_sha} ${external_id}`);
return;
}
console.log('Latest integration-test-result check run:', run.html_url)
await github.rest.checks.update({
...context.repo,
check_run_id: run.id,
status: "completed",
conclusion: context.payload.workflow_run.conclusion,
});
return run.id
32 changes: 10 additions & 22 deletions .github/workflows/mergify-ready.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,8 @@ jobs:
wait-integration-pre-checks:
runs-on: ubuntu-latest
steps:
- name: Create integration-test-result check
id: create-check
if: always()
uses: actions/github-script@v6
with:
script: |
const head_sha = context.eventName === 'pull_request' ?
context.payload.pull_request.head.sha : context.sha
const res = await github.rest.checks.create({
...context.repo,
head_sha,
name: "integration-test-result",
})
core.debug('check create response: ${JSON.stringify(res, null, 2)}')
console.log('created integration-test-result', res.data.html_url)
return res.data.id
outputs:
run_id: ${{ steps.create-check.outputs.result }}
- shell: bash
run: echo "TODO remove this vestigial job"

merge-strategy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -74,10 +58,14 @@ jobs:
fetch-depth: 0
- shell: bash
run: |
merge_commits=$(git rev-list --merges "origin/$GITHUB_BASE_REF".."origin/$GITHUB_HEAD_REF")
HEAD_SHA=${{ github.event.pull_request.head.sha }}
HEAD_LABEL="${{ github.event.pull_request.head.label }}"
BASE_SHA=${{ github.event.pull_request.base.sha }}
BASE_LABEL="${{ github.event.pull_request.base.label }}"
merge_commits=$(git rev-list --merges "$BASE_SHA".."$HEAD_SHA")
if [ -n "$merge_commits" ]; then
echo "Error: merge commits found in $GITHUB_BASE_REF..$GITHUB_HEAD_REF"
echo "Error: merge commits found in $BASE_LABEL..$HEAD_LABEL"
for merge_commit in $merge_commits; do
echo "$merge_commit"
Expand All @@ -87,15 +75,15 @@ jobs:
fi
fixup_commits=
for commit in $(git rev-list $GITHUB_BASE_REF..$GITHUB_HEAD_REF); do
for commit in $(git rev-list $BASE_SHA..$HEAD_SHA); do
case $(git show --pretty=format:%s -s $commit) in fixup\!*|squash\!*)
fixup_commits="$fixup_commits\n$commit"
;;
esac
done
if [ -n "$fixup_commits" ]; then
echo "Error: fixup/squash commits found in $GITHUB_BASE_REF..$GITHUB_HEAD_REF"
echo "Error: fixup/squash commits found in $BASE_LABEL..$HEAD_LABEL"
echo -e "$fixup_commits"
exit 1
fi
9 changes: 6 additions & 3 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pull_request_rules:
- '#commits-behind=0'
- label=bypass:linear-history
- or:
- check-success=wait-integration-pre-checks
- check-pending=integration-test-result
- check-success=integration-test-result
- label=bypass:integration
- or:
- and: # breakage succeeds like we thought
Expand All @@ -35,7 +36,8 @@ pull_request_rules:
- base=master
- label=automerge:rebase
- or:
- check-success=wait-integration-pre-checks
- check-pending=integration-test-result
- check-success=integration-test-result
- label=bypass:integration
- or:
- and: # breakage succeeds like we thought
Expand All @@ -54,7 +56,8 @@ pull_request_rules:
- base=master
- label=automerge:squash
- or:
- check-success=wait-integration-pre-checks
- check-pending=integration-test-result
- check-success=integration-test-result
- label=bypass:integration
- or:
- and: # breakage succeeds like we thought
Expand Down

0 comments on commit 6d81783

Please sign in to comment.