-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (153 loc) · 5.85 KB
/
scrape-and-build.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: "Scrape and Build"
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
jobs:
scrape:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.scrapejob.outputs.result }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
working-directory: scripts
- id: scrapejob
run: npm run scrape
working-directory: scripts
env:
GITHUB_TOKEN: ${{ github.token }}
build:
needs: scrape
runs-on: ubuntu-latest
strategy:
matrix:
job: ${{ fromJSON(needs.scrape.outputs.result) }}
permissions:
contents: write
issues: write
env:
SOURCE_OWNER: ${{ fromJSON(matrix.job).source.owner }}
SOURCE_REPOSITORY: ${{ fromJSON(matrix.job).source.repository }}
SOURCE_TAG: ${{ fromJSON(matrix.job).source.tag }}
IMAGE_REPOSITORY: ${{ fromJSON(matrix.job).image.repository }}
IMAGE_TAG: ${{ fromJSON(matrix.job).image.tag }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
with:
repository: ${{ env.SOURCE_OWNER }}/${{ env.SOURCE_REPOSITORY }}
ref: ${{ env.SOURCE_TAG }}
path: ${{ env.SOURCE_REPOSITORY }}
- uses: actions/checkout@v3
with:
path: stocker
- name: Build image
run: |
exec 2> >(tee -a /tmp/error.log >&2) > >(tee -a /tmp/out.log)
docker build \
--file stocker/repositories/${{ env.IMAGE_REPOSITORY }}/Dockerfile \
--tag ${{ vars.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }} \
--build-arg SOURCE_OWNER=${{ env.SOURCE_OWNER }} \
--build-arg SOURCE_REPOSITORY=${{ env.SOURCE_REPOSITORY }} \
--build-arg SOURCE_TAG=${{ env.SOURCE_TAG }} \
--build-arg IMAGE_REPOSITORY=${{ env.IMAGE_REPOSITORY }} \
--build-arg IMAGE_TAG=${{ env.IMAGE_TAG }} \
${{ env.SOURCE_REPOSITORY }}
- name: Test image
env:
IMAGE: ${{ vars.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}
working-directory: stocker/repositories/${{ env.IMAGE_REPOSITORY }}
run: |
exec 2> >(tee -a /tmp/error.log >&2) > >(tee -a /tmp/out.log)
./test.bash
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
working-directory: stocker/scripts
- run: npm run createDockerhubRepository
working-directory: stocker/scripts
env:
INPUT_USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
INPUT_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
INPUT_REPOSITORY: ${{ env.IMAGE_REPOSITORY }}
- run: npm run updateDockerhubRepository
working-directory: stocker/scripts
env:
INPUT_USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
INPUT_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
INPUT_REPOSITORY: ${{ env.IMAGE_REPOSITORY }}
INPUT_FULL_DESCRIPTION_PATH: ${{ env.SOURCE_REPOSITORY }}/README.md
- uses: docker/login-action@v1
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push image
run: |
exec 2> >(tee -a /tmp/error.log >&2) > >(tee -a /tmp/out.log)
docker push ${{ vars.DOCKERHUB_USERNAME }}/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: Create success history file
if: ${{ success() }}
working-directory: stocker
run: |
mkdir -p .history/${{ env.IMAGE_REPOSITORY }}
cat <<- EOF > .history/${{ env.IMAGE_REPOSITORY }}/${{ env.IMAGE_TAG }}
Successfully built and pushed stocker/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}
EOF
- name: Create failure history file
if: ${{ failure() }}
working-directory: stocker
run: |
mkdir -p .history/${{ env.IMAGE_REPOSITORY }}
cat <<- EOF > .history/${{ env.IMAGE_REPOSITORY }}/${{ env.IMAGE_TAG }}
Failed to build stocker/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}
---
EOF
- name: View failed job log
if: ${{ failure() }}
id: failure
run: |
set -Eeuo pipefail
echo "log=$(cat /tmp/error.log)" >> $GITHUB_OUTPUT
working-directory: stocker
- name: Append failed job log to history file
run: echo ${{ steps.failure.outputs.log }} >> .history/${{ env.IMAGE_REPOSITORY }}/${{ env.IMAGE_TAG }}
if: ${{ failure() }}
working-directory: stocker
- name: Update repository with history file
if: ${{ success() || failure() }}
working-directory: stocker
timeout-minutes: 5
run: |
set +e
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add .history/${{ env.IMAGE_REPOSITORY }}/${{ env.IMAGE_TAG }}
git commit -m "Update history file for stocker/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}"
git push
while [ $? -ne 0 ]; do
git pull --rebase
git push && break
sleep 5
done
- name: Create issue
if: ${{ failure() }}
uses: actions-ecosystem/action-create-issue@v1
with:
title: "Failed to build stocker/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }}"
body: |
The build of stocker/${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }} failed.
```
${{ steps.failure.outputs.log }}
```
labels: "bug"
github_token: ${{ github.token }}