-
Notifications
You must be signed in to change notification settings - Fork 51
161 lines (146 loc) · 5.7 KB
/
install-slices.yaml
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
name: Install slices
on:
push:
branches:
- "main"
paths:
- ".github/scripts/install-slices/**"
- ".github/workflows/install-slices.yaml"
pull_request:
branches:
- "main"
paths:
- ".github/scripts/install-slices/**"
- ".github/workflows/install-slices.yaml"
schedule:
# Run at 00:00 every day.
# Ref: https://man7.org/linux/man-pages/man5/crontab.5.html
- cron: "0 0 * * *"
workflow_call:
env:
# Package architectures and chisel-releases branches to test on.
ARCHES: ${{ toJson('["amd64","arm64","armhf","i386","ppc64el","riscv64","s390x"]') }}
RELEASES: ${{ toJson('["ubuntu-20.04","ubuntu-22.04","ubuntu-24.04"]') }}
jobs:
prepare-install:
runs-on: ubuntu-latest
name: "Prepare to install"
outputs:
install-all: ${{ steps.set-output.outputs.install_all }}
matrix: ${{ steps.set-output.outputs.matrix }}
checkout-main-ref: ${{ steps.set-output.outputs.checkout_main_ref }}
steps:
- name: Set output
id: set-output
run: |
set -ex
if [[
"${{ github.base_ref || github.ref_name }}" == "main" ||
"${{ github.event_name }}" == "schedule"
]]; then
echo "matrix={\"ref\":${{ env.RELEASES }},\"arch\":${{ env.ARCHES }}}" >> $GITHUB_OUTPUT
echo "install_all=true" >> $GITHUB_OUTPUT
else
echo "matrix={\"arch\":${{ env.ARCHES }}}" >> $GITHUB_OUTPUT
fi
if [[ "${{ github.base_ref }}" == "main" ]]; then
# For PRs to main, use the updated files.
# Leaving checkout_main_ref unset will checkout the PR head_ref.
echo "checkout_main_ref=" >> $GITHUB_OUTPUT
else
echo "checkout_main_ref=main" >> $GITHUB_OUTPUT
fi
# The "install" job tests the slices by installing them.
# It installs **all** slices if:
# - chisel.yaml is changed
# - any slice definition files are deleted
# - github workflows (and related files) are changed
# Otherwise, it installs only the slices from **added** and/or
# **modified** slice definition files.
# Please note that "change" is defined to encompass additions,
# modifications and deletions here.
install:
runs-on: ubuntu-latest
name: "Install"
needs: prepare-install
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-install.outputs.matrix) }}
env:
install-all: ${{ needs.prepare-install.outputs.install-all }}
main-branch-ref: ${{ needs.prepare-install.outputs.checkout-main-ref }}
main-branch-path: files-from-main
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ matrix.ref }}
- name: Check changed paths
id: changed-paths
if: env.install-all != 'true'
uses: dorny/paths-filter@v3
with:
# ref: https://github.com/marketplace/actions/paths-changes-filter
filters: |
install-all:
- 'chisel.yaml'
- deleted: 'slices/**/*.yaml'
- '.github/**'
slices:
- added|modified: 'slices/**/*.yaml'
# Space delimited list usable as command-line argument list in
# Linux shell. If needed, it uses single or double quotes to
# wrap filename with unsafe characters.
list-files: shell
- name: Setup Go environment
uses: actions/setup-go@v5
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: ${{ env.main-branch-ref }}
path: ${{ env.main-branch-path }}
- name: Install dependencies
env:
script-dir: "${{ env.main-branch-path }}/.github/scripts/install-slices"
run: |
set -ex
# Install chisel
go install github.com/canonical/chisel/cmd/chisel@main
# Install dependencies of the install_slices script
sudo apt-get -y update
sudo apt-get install -y $(cat "${{ env.script-dir }}/deb-requirements.txt")
pip install -r "${{ env.script-dir }}/requirements.txt"
# Configure the path of install_slices script
ln -s "${{ env.script-dir }}/install_slices.py" install-slices
# TODO: As we are installing the slices for every (ref, arch), when
# installing all slices, we are also checking the existence of every
# package for at least one architecture in a particular release. This
# means that we are running the same check for every arch while running it
# for just one arch would have been enough. We should revisit this in
# future and propose improvements.
# See also https://github.com/canonical/chisel-releases/pull/119#discussion_r1494785644
- name: Install slices
run: |
set -ex
if [[
"${{ env.install-all }}" == "true" ||
"${{ steps.changed-paths.outputs.install-all }}" == "true"
]]; then
# Install all slices in slices/ dir.
# We need to enable globstar to use the ** patterns below.
shopt -s globstar
./install-slices --arch "${{ matrix.arch }}" --release ./ \
--ensure-existence \
--ignore-missing \
slices/**/*.yaml
elif [[ "${{ steps.changed-paths.outputs.slices }}" == "true" ]]; then
# Install slices from changed files.
./install-slices --arch "${{ matrix.arch }}" --release ./ \
--ensure-existence \
--ignore-missing \
${{ steps.changed-paths.outputs.slices_files }}
fi