generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
234 lines (207 loc) · 7.76 KB
/
features.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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
---
name: Features
on:
pull_request:
branches:
- main
paths:
- features/**
push:
branches:
- main
paths:
- features/**
permissions: {}
jobs:
detect-changes:
name: Detect Changes
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
features: ${{ steps.detect_changes.outputs.changes }}
steps:
- name: Checkout
id: checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Build path-filters file
id: build_path_filters
run: bash scripts/path-filter/configuration-generator.sh features
- name: Detect changes
id: detect_changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
with:
filters: .github/path-filters/features.yml
preflight-checks:
needs: [detect-changes]
if: ${{ needs.detect-changes.outputs.features != '[]' && github.ref != 'refs/heads/main' }}
name: Preflight Checks
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
packages: read
strategy:
fail-fast: false
matrix:
feature: ${{ fromJson(needs.detect-changes.outputs.features) }}
steps:
- name: Checkout
id: checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Check Version
id: check_version
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "${{ env.GH_TOKEN }}" | skopeo login ghcr.io --username ${{ github.actor }} --password-stdin
version=$(jq -r '.version' features/src/${{ matrix.feature }}/devcontainer-feature.json)
export version
if skopeo list-tags docker://ghcr.io/ministryofjustice/devcontainer-feature/${{ matrix.feature }}; then
feature_exists=true
else
echo "feature_exists=false" >>"${GITHUB_ENV}"
echo "tag_exists=false" >>"${GITHUB_ENV}"
fi
if [[ "${feature_exists}" == "true" ]]; then
checkTag=$(skopeo list-tags docker://ghcr.io/ministryofjustice/devcontainer-feature/${{ matrix.feature }} | jq -r --arg version "${version}" '.Tags | index($version)')
export checkTag
if [[ -z "${imageTag}" ]]; then
echo "tag_exists=false" >>"${GITHUB_ENV}"
else
echo "tag_exists=true" >>"${GITHUB_ENV}"
fi
fi
- name: Check CHANGELOG Updates
id: check_changelog_updates
env:
GH_TOKEN: ${{ github.token }}
run: |
mainSha=$(gh api --method GET /repos/"${GITHUB_REPOSITORY}"/contents/features/src/${{ matrix.feature }}/CHANGELOG.md --field ref="main" | jq -r '.sha')
branchSha=$(gh api --method GET /repos/"${GITHUB_REPOSITORY}"/contents/features/src/${{ matrix.feature }}/CHANGELOG.md --field ref="${GITHUB_HEAD_REF}" | jq -r '.sha')
if [[ -z "${mainSha}" ]]; then
SHA not found for main branch, assuming CHANGELOG.md does not exist
elif [[ -z "${branchSha}" ]]; then
SHA not found for "${GITHUB_HEAD_REF}" branch, assuming CHANGELOG.md does not exist
"changelog_updated=false" >>"${GITHUB_ENV}"
elif [[ "${mainSha}" == "${branchSha}" ]]; then
echo "CHANGELOG.md matches main branch, needs to be updated"
echo "changelog_updated=false" >>"${GITHUB_ENV}"
elif [[ "${mainSha}" != "${branchSha}" ]]; then
echo "CHANGELOG.md does not match main branch, does not need to be updated"
echo "changelog_updated=true" >>"${GITHUB_ENV}"
fi
- name: Evaluate Checks
id: evaluate_checks
run: |
if [[ "${{ env.tag_exists }}" == "true" ]]; then
echo "::error::FAIL: Feature tag already exists"
export failBuild="true"
else
echo "::notice::OK: Feature tag does not exist"
export failBuild="false"
fi
if [[ "${{ env.changelog_updated }}" == "true" ]]; then
echo "::notice::OK: CHANGELOG.md has been updated"
export failBuild="false"
elif [[ "${{ env.changelog_updated }}" == "false" ]]; then
echo "::error::FAIL: CHANGELOG.md needs to be updated"
export failBuild="true"
fi
if [[ "${failBuild}" == "true" ]]; then
exit 1
fi
test:
needs: [detect-changes]
if: ${{ needs.detect-changes.outputs.features != '[]' && github.ref != 'refs/heads/main' }}
name: Test
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
feature: ${{ fromJson(needs.detect-changes.outputs.features) }}
steps:
- name: Checkout
id: checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install @devcontainers/cli
id: install_devcontainers_cli
run: npm install --global @devcontainers/cli@latest
- name: Build Image
id: build_image
uses: docker/build-push-action@b32b51a8eda65d6793cd0494a773d4f6bcef32dc # v6.11.0
with:
file: images/base/Dockerfile
context: images/base
load: true
tags: ghcr.io/ministryofjustice/devcontainer-base:local-feature-test
- name: Testing ${{ matrix.feature }}
id: test_feature
run: |
devcontainer features test \
--skip-duplicated \
--skip-scenarios \
--project-folder features \
--features ${{ matrix.feature }} \
--base-image ghcr.io/ministryofjustice/devcontainer-base:local-feature-test
- name: Testing ${{ matrix.feature }} scenarios
id: test_feature_scenarios
run: |
devcontainer features test \
--project-folder features \
--features ${{ matrix.feature }} \
--skip-autogenerated \
--skip-duplicated \
--base-image ghcr.io/ministryofjustice/devcontainer-base:local-feature-test
validate:
needs: [detect-changes]
if: ${{ needs.detect-changes.outputs.features != '[]' && github.ref != 'refs/heads/main' }}
name: Validate
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
id: checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Validate
uses: devcontainers/action@1082abd5d2bf3a11abccba70eef98df068277772 # v1.4.3
with:
validate-only: true
base-path-to-features: features/src
publish:
needs: [detect-changes]
if: ${{ needs.detect-changes.outputs.features != '[]' && github.ref == 'refs/heads/main' }}
name: Publish
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
packages: write
strategy:
fail-fast: false
matrix:
feature: ${{ fromJson(needs.detect-changes.outputs.features) }}
steps:
- name: Checkout
id: checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Log in to GitHub Container Registry
id: login_ghcr
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install @devcontainers/cli
id: install_devcontainers_cli
run: npm install --global @devcontainers/cli@latest
- name: Publish
id: publish
run: |
devcontainer features publish \
--registry ghcr.io \
--namespace ministryofjustice/devcontainer-feature \
./features/src/${{ matrix.feature }}