Repository navigation
188 lines (165 loc) · 6.91 KB
/
Copy pathpull-request.yml
File metadata and controls
188 lines (165 loc) · 6.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#
# This workflow is run for pull requests the modify the `packages` directory.
# It works in two stages: first it determines the list of added, modified or
# removed packages; for each added or modified package, it executes the
# `validate_package.py` script to check for issues with the metadata or
# tarball. Provided these initial tests pass, the second stage consists of
# invoking a separate workflow which runs tests for all packages in the
# package distribution as they would appear when the PR under review would be
# merged. This is used to determine whether any package tests change from PASS
# to FAIl or vice versa.
#
name: "PR"
on:
workflow_dispatch: # manual trigger for debugging
pull_request:
paths:
- 'packages/*/meta.json'
concurrency:
# group by workflow and ref
group: ${{ github.workflow }}-${{ github.ref }}
# Cancel intermediate builds, but only if it is a pull request build.
cancel-in-progress: true
jobs:
detect-changes:
name: "Detect affected packages"
runs-on: ubuntu-latest
if: ${{ !contains( github.event.pull_request.labels.*.name, 'skip tests') }}
outputs:
modified: ${{ steps.modified.outputs.modified }}
steps:
# clone with depth 0, so that we can determine what was changed
# TODO: isn't depth 1 sufficient?
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: "Set up Python"
uses: actions/setup-python@v7
with:
python-version: "3.11"
- name: "Install package distribution tools"
run: python -m pip install -r tools/requirements.txt
# the following step is useful for debugging
- name: "Determine system architecture for -march=native"
run: |
echo "cc -march=native: $(tools/compiler_arch.sh cc)"
echo "c++ -march=native: $(tools/compiler_arch.sh c++)"
# Setup ccache, to speed up repeated compilation of the same binaries
# (i.e., GAP and the packages)
- name: "Setup ccache"
uses: Chocobo1/setup-ccache-action@v1
with:
update_packager_index: false
- name: "Install GAP"
uses: gap-actions/setup-gap@v3
- name: "Build the json package"
run: |
cd ${GAPROOT}/pkg
../bin/BuildPackages.sh --strict json
- name: "Determine what was added or modified, validate"
id: modified
run: |
modified=$(git diff --name-only --no-renames --diff-filter=AM ${{ github.event.pull_request.base.sha }} -- packages/*/meta.json)
echo "Added or updated packages: ${modified}"
if [[ -n "${modified}" ]]; then
echo "modified=true" >> $GITHUB_OUTPUT
else
echo "modified=false" >> $GITHUB_OUTPUT
fi
echo "Obtain copies of old metadata, if any..."
for PKG in ${modified}; do
git cat-file blob ${{ github.event.pull_request.base.sha }}:$PKG > $PKG.old || rm -f $PKG.old
done
echo "Validate metadata..."
tools/validate_package.py ${modified}
test-all-master:
name: "master"
needs: detect-changes
if: ${{ needs.detect-changes.outputs.modified == 'true' }}
uses: ./.github/workflows/test-all.yml
with:
which-gap: 'master'
# test-all-release:
# name: "4.12.2"
# needs: detect-changes
# if: ${{ needs.detect-changes.outputs.modified == 'true' }}
# uses: ./.github/workflows/test-all.yml
# with:
# which-gap: '4.12.2'
status-comment:
name: "Create or update PR comment"
runs-on: ubuntu-slim
needs: test-all-master # TODO: also handle test-all-release
if: always()
steps:
- name: "Download report"
uses: actions/download-artifact@v8
with:
name: report-master
path: _report
- name: "Prepare report.md"
id: get-comment-body
run: |
echo "body<<EOF1234567890EOF" >> $GITHUB_OUTPUT
cat _report/report.md >> $GITHUB_OUTPUT
echo "EOF1234567890EOF" >> $GITHUB_OUTPUT
- name: "Find Comment"
uses: peter-evans/find-comment@v4
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
# comment-author: "gap-package-distribution-bot <100730870+gap-package-distribution-bot[bot]@users.noreply.github.com>"
body-includes: "Package Evaluation Report"
# We set up a GitHub App in order to ensure that workflows are run on the PRs
# created by us, following the instructions here:
# <https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens>
# The bot can also be set up for personal forks of this repository, for testing
# and debugging, see <https://github.com/apps/gap-package-distribution-bot>.
- uses: actions/create-github-app-token@v3
id: generate-token
with:
client-id: ${{ vars.APP_CLIENT_ID || secrets.APP_CLIENT_ID || secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
# TODO: extra work is needed to make the following work with pull requests
# that come from forks of this repository.
- name: "Create or update comment"
uses: peter-evans/create-or-update-comment@v5
with:
token: ${{ steps.generate-token.outputs.token }}
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.get-comment-body.outputs.body }}
edit-mode: replace
package-tests-passed:
name: "Package tests passed"
runs-on: ubuntu-slim
needs:
- detect-changes
- test-all-master
# This job is intended to be the stable required check for branch
# protection / rulesets. The called test-all workflow expands to many
# package jobs, and their names change as packages are added or removed.
#
# Keep this as `always()` and fail explicitly below: GitHub treats skipped
# required checks as successful, so this gate must not be skipped when an
# upstream job fails or is skipped.
if: always()
steps:
- name: "Check package test workflow result"
run: |
if [[ "${{ needs.detect-changes.result }}" != "success" ]]; then
echo "The affected-package detection job did not pass."
echo "Result: ${{ needs.detect-changes.result }}"
exit 1
fi
if [[ "${{ needs.detect-changes.outputs.modified }}" != "true" ]]; then
echo "No added or modified package metadata was found."
echo "Refusing to mark package tests as passed."
exit 1
fi
if [[ "${{ needs.test-all-master.result }}" != "success" ]]; then
echo "The package test workflow did not pass."
echo "Result: ${{ needs.test-all-master.result }}"
exit 1
fi
echo "The package test workflow passed."