-
Notifications
You must be signed in to change notification settings - Fork 29
180 lines (154 loc) · 4.69 KB
/
ci.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
name: CI
on:
pull_request:
workflow_call:
inputs:
push:
type: boolean
description: To push built images or not
default: false
outputs:
restylers:
description: Changed restylers
value: ${{ jobs.changes.outputs.restylers }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
DOCKER_BUILD_SUMMARY: "false"
DOCKER_BUILD_RECORD_UPLOAD: "false"
LOG_COLOR: always
LOG_CONCURRENCY: 1
LOG_BREAKPOINT: 200
jobs:
tools:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: stack
uses: freckle/stack-action@v5
with:
working-directory: _tools
- uses: actions/upload-artifact@v4
with:
name: tools
path: "${{ steps.stack.outputs.local-install-root }}/bin/*"
if-no-files-found: error
changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: changes
uses: dorny/paths-filter@v3
with:
filters: |
all: '**/*'
list-files: shell
- id: filtered
name: Identify Restyler changes
run: ./.github/bin/filter-changes ${{ steps.changes.outputs.all_files }}
outputs:
restylers: ${{ steps.filtered.outputs.restylers }}
restylers:
needs:
- tools
- changes
if: ${{ needs.changes.outputs.restylers }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: tools
- name: Install tools
run: |
chmod +x ./restylers
sudo mv -v restylers /usr/local/bin
curl --proto '=https' --tlsv1.2 -sSf \
https://raw.githubusercontent.com/restyled-io/restyler/main/install | sudo sh
- if: ${{ inputs.push }}
name: AWS Login
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: ${{ vars.AWS_ROLE }}
- if: ${{ inputs.push }}
name: Create ECR repositories if necessary
run: |
for name in ${{ needs.changes.outputs.restylers }}; do
rname=restyler-$name
if ! aws ecr-public describe-repositories --repository-names "$rname" &>/dev/null; then
echo "Creating ECR repository for $rname"
aws ecr-public create-repository --repository-name "$rname"
fi
done
- if: ${{ inputs.push }}
name: ECR Login
id: ecr-login
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Build${{ inputs.push && ', test, and push' || ' and test'}}
run: >-
restylers
${{ runner.debug && '--debug' || '' }}
--write tested.yaml
--no-pull
${{ inputs.push && '--push' || '' }}
${{ needs.changes.outputs.restylers }}
- name: Build merged restylers.yaml
run: |
gh release download dev -p restylers.yaml
mv -v restylers.yaml base.yaml
ruby -r yaml > restylers.yaml <<'EOM'
base = YAML.safe_load_file("./base.yaml")
tested = YAML.safe_load_file("./tested.yaml")
merged = base.map do |b|
tested.find { _1.fetch("name") == b.fetch("name") } || b
end
puts YAML.dump(merged)
EOM
echo "::group::Merged manifest"
cat restylers.yaml
echo "::endgroup::"
echo "::group::Changes"
diff -U 3 base.yaml restylers.yaml || true
echo "::endgroup::"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Test manifest
- uses: restyled-io/actions/setup-demo@v4
- uses: restyled-io/actions/setup@v4
- uses: restyled-io/actions/run@v4
with:
paths: .
manifest: ./restylers.yaml
dry-run: true
- uses: actions/upload-artifact@v4
with:
name: manifest
path: restylers.yaml
if-no-files-found: error
lint:
needs: changes
if: ${{ needs.changes.outputs.restylers }}
runs-on: ubuntu-latest
steps:
- id: prep
run: |
{
printf 'dockerfiles='
for restyler in ${{ needs.changes.outputs.restylers }}; do
printf './%s/Dockerfile ' "$restyler"
done
echo
} >>"$GITHUB_OUTPUT"
- uses: actions/checkout@v4
- uses: hadolint/hadolint-action@master
with:
dockerfile: ${{ steps.prep.outputs.dockerfiles }}
failure-threshold: error