-
Notifications
You must be signed in to change notification settings - Fork 2
199 lines (173 loc) · 6.73 KB
/
main.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
# This is a basic workflow to help you get started with Actions
name: CI.build.template
# Controls when the action will run. Triggers the workflow on push or pull request
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
pull_request:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
generateInputDockerFile:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
commit_hash: ${{ steps.set-matrix.outputs.commit_hash }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "18.x"
- name: Install dependencies
run: npm install
- name: generate Dockerfiles
run: node make.js -r ${{ github.ref_name }}
- name: Generate matrix with all Dockerfiles of the repository
id: set-matrix
run: |
dockerfiles=$(ls -l *.d | grep '^-' | awk -F ' ' '{print $9}' | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "dockerfiles=$dockerfiles"
# dockerfiles is an array of filename
# echo "::set-output name=matrix::$dockerfiles"
echo "matrix=$dockerfiles" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v4
with:
name: artifact-dockerfiles
path: "*.d"
if-no-files-found: warn # 'error' or 'ignore' are also available, defaults to `warn`
build:
needs: generateInputDockerFile
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
outputs:
matrix: ${{ steps.set-jsonimage.outputs.matrix }}
strategy:
fail-fast: false
matrix:
path: ${{ fromJson(needs.generateInputDockerFile.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
# overwrite previous Dockerfiles
- uses: actions/download-artifact@v4
with:
name: artifact-dockerfiles
- name: Current Dockerfile
run: |
echo Dockerfile ${{ matrix.path }}
ls -la ${{ matrix.path }}
cat ${{ matrix.path }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Define platforms
id: define-platforms
run: |
PLATFORMS=$(grep "# platforms=" ${{ matrix.path }} | awk -F "=" '{print $2 }')
echo "platforms=$PLATFORMS"
echo "platforms=$PLATFORMS" >> "$GITHUB_OUTPUT"
- name: Build and push ${{ matrix.path }}
env:
image: ${{ matrix.path }}
imagetag: ${{ github.ref_name || 'main' }}
uses: docker/build-push-action@v5
with:
file: ${{ env.image }}
context: .
platforms: ${{ steps.define-platforms.outputs.platforms }}
build-args: |
TAG=${{ env.imagetag }}
push: true
tags: |
abcdesktopio/${{ env.image }}:${{ env.imagetag }}
- uses: actions/upload-artifact@v4
env:
image: ${{ matrix.path }}
imagetag: ${{ github.ref_name || 'main' }}
with:
name: artifact.${{ env.image }}.${{ env.imagetag }}
path: ${{ env.image }}
if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`
- name: Repository Dispatch
env:
image: ${{ matrix.path }}
imagetag: ${{ github.ref_name || 'main' }}
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.TOKEN_DISPATCH }}
repository: abcdesktopio/images
event-type: dispatch-from-oc.apps
client-payload: '{ "ref_name": "${{ github.ref_name }}", "image": "${{ env.image }}", "tag": "${{ env.imagetag }}"}'
generateDocumentation:
needs: build
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- uses: actions/download-artifact@v4
with:
name: artifact-dockerfiles
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "18.x"
- name: Install dependencies
run: npm install
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: generate MarkDown files
run: |
node make-docs.js --release ${{ github.head_ref }}
- uses: actions/upload-artifact@v4
with:
name: artifact-application-md-files
path: "*.md"
if-no-files-found: error # 'error' or 'ignore' are also available, defaults to `warn`
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.TOKEN_DISPATCH }}
repository: abcdesktopio/docs
event-type: dispatch-from-oc.apps
client-payload: '{ "ref_name": "${{ github.head_ref }}", "repository": "${{ github.repository }}", "run_id": "${{ github.run_id }}", "artifact": "artifact-application-md-files" }'
#- name: commit Dockerfiles and md files
# env:
# CI_COMMIT_MESSAGE: Continuous Integration Build Artifacts
# CI_COMMIT_AUTHOR: ${{ github.event.repository.name }} Continuous Integration
# uses: nick-fields/retry@v2
# with:
# timeout_minutes: 10
# max_attempts: 3
# command: |
# git config --global pull.ff only
# git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
# git config --global user.email "[email protected]"
# git add *.md *.d
# git commit -m "${{ env.CI_COMMIT_MESSAGE }}" *.md
# git push origin ${{ github.head_ref }}