-
Notifications
You must be signed in to change notification settings - Fork 8
158 lines (138 loc) · 5.88 KB
/
scan-for-updates.yml
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
#
# This workflow is run regularly and scans for package updates, by
# downloading the file specified by the `PackageInfoURL` in each package
# and comparing it against what was there already.
#
# Then for each package where a diff is found, a new `CI` job is created,
# see `create-pull-request` below, which creates a pull request updating
# the package. Note that we perform no validation of the update here;
# that is a task for the GItHub workflow in `pull-request.yml`.
#
name: "Scan for updates"
on:
workflow_dispatch: # for debugging
inputs:
pkginfo_urls:
description: 'A space separated list of PackageInfo.g URLs'
required: false
type: string
default: ''
schedule:
- cron: '3 * * * *' # Every hours at 3 past
jobs:
scan-for-updates:
name: "Scan for package updates"
runs-on: ubuntu-20.04
outputs:
matrix: ${{ steps.get-names.outputs.matrix }}
steps:
- uses: actions/checkout@v4
# Cache the package archives we download across runs of this job
# to speed up things considerably
- name: "Cache archives"
uses: actions/cache@v4
with:
path: _archives
key: archives-${{ hashFiles('packages/*/meta.json') }}
restore-keys: |
archives-
# 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@v2
with:
GAP_BOOTSTRAP: 'minimal'
GAP_PKGS_TO_CLONE: 'crypting json'
GAP_PKGS_TO_BUILD: 'crypting json'
- name: "Install prerequisites for package distribution tools"
run: python -m pip install -r tools/requirements.txt
- name: "Scan for updates"
run: tools/scan_for_updates.py
- name: "Import user specified packages"
run: |
tools/import_packages.py ${{ github.event.inputs.pkginfo_urls }}
# remove archives we don't need anymore; this reduces the size of the caches
- name: "Cleanup archives"
run: tools/cleanup_archives.py
# The following builds a job matrix; we launch a copy of the "create-pull-request"
# for each package whose meta.json was modified or added
- name: "Create jobs for modified packages"
id: get-names
run: |
# detect all added or modified files in the `packages` directory
modified=$(git status --porcelain -uall -- packages/*/meta.json | cut -c4-)
# create an archive of the added or modified files, to be uploaded as an
# artifact in the next step, and for use by subsequent jobs
# HACK: add 'LICENSE' to the files in the archive, to avoid
# creating an empty archive when there are no modified files
tar cvf modified.tar.gz $modified LICENSE
# create the actual build matrix
jobnames=$(tools/group_packages.py $modified)
MATRIX="{\"package_or_group\":["
for PKG in ${jobnames}; do
echo "${PKG}"
MATRIX="${MATRIX}\"${PKG}\","
done
MATRIX="${MATRIX}]}"
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
- name: "Upload metadata as artifact for pull request jobs"
uses: actions/upload-artifact@v4
with:
name: metadata
path: modified.tar.gz
create-pull-request:
name: "Create pull request for ${{ matrix.package_or_group }}"
if: ${{ needs.scan-for-updates.outputs.matrix != '{"package_or_group":[]}' }}
needs: scan-for-updates
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.scan-for-updates.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: "Download metadata from previous job"
uses: actions/download-artifact@v4
with:
name: metadata
- name: "Prepare pull request"
run: |
tar xvf modified.tar.gz
# detect all added or modified files in the `packages` directory
modified=$(git status --porcelain -uall -- packages/*/meta.json | cut -c4-)
echo "modified:"
echo "$modified"
tools/prepare_pr.py ${{ matrix.package_or_group }} $modified >> $GITHUB_ENV
cat $GITHUB_ENV
# 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: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: peter-evans/create-pull-request@v6
with:
token: ${{ steps.generate-token.outputs.token }}
# https://api.github.com/users/gap-package-distribution-bot%5Bbot%5D
author: "gap-package-distribution-bot <100730870+gap-package-distribution-bot[bot]@users.noreply.github.com>"
add-paths: ${{ env.PR_FILES }}
commit-message: "${{ env.PR_TITLE }}"
body: ${{ env.PR_BODY }}
branch: automatic/${{ matrix.package_or_group }}
delete-branch: true
title: "${{ env.PR_TITLE }}"
labels: |
automated pr
${{ env.PR_LABEL }}