-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (153 loc) · 6.09 KB
/
build.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
name: Build
on:
push:
branches: [ main, 'develop/**' ]
jobs:
matrix: # sets the matrix
runs-on: ubuntu-latest
outputs:
plugin: ${{ steps.matrix.outputs.plugin }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
dir_names: "true"
since_last_remote_commit: true
files_ignore: |
**/*.md
**/**.md
**/assets/**
**/docs/**
.github/**
Dockerfile
Makefile
- name: Set the plugins matrix
id: matrix
run: |
directories=$(echo ${{ steps.changed-files.outputs.all_changed_and_modified_files }} | awk '{for (i=1; i<=NF; i++) {sub(/\/.*/, "", $i); printf "%s ", $i}}' | xargs -n1 | sort -u) # get main directory and remove duplicate directories
matrix=$((
echo '{ "plugin" : ['
separator=''
for d in $directories; do
[[ $d != "." ]] || continue;
[[ $d != ".github"* ]] || continue;
[[ $d != *"/"* ]] || continue;
[[ $d != "_"* ]] || continue;
[[ $d != *".md" ]] || continue;
[[ $d != *"/assets/"* ]] || continue;
echo -n "$separator"\""$d"\"; separator=',';
done
echo "]}"
) | jq -c .)
# if branch is develop/<plugin> keep in matrix only the plugin if it exists
branch=${GITHUB_REF#refs/heads/}
if [[ "$branch" == "develop/"* ]]; then
plugins=${branch#develop/}
if echo "$matrix" | jq -e --arg value "$plugins" '.plugin | index($value)' > /dev/null; then
matrix='{"plugin":["'$plugins'"]}'
else
matrix='{"plugin":[]}'
fi
fi
echo "plugin=$matrix" >> $GITHUB_OUTPUT
- name: Check content of matrix
run: echo ${{ steps.matrix.outputs.plugin }}
build:
if: ${{ needs.matrix.outputs.plugin != '{"plugin":[]}' }} # check if matrix is not empty
runs-on: ubuntu-latest
needs: matrix
strategy:
fail-fast: false # continues with matrix even if an element fails
matrix: ${{fromJson(needs.matrix.outputs.plugin)}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract branch name
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- name: Get image version
run: |
if [[ "${{ env.branch }}" == "main" ]]; then
echo docker_version=`jq '.version' ./${{ matrix.plugin }}/plugin.json | tr -d \"` >> $GITHUB_ENV
echo version=v`jq '.version' ./${{ matrix.plugin }}/plugin.json | tr -d \"` >> $GITHUB_ENV
else
echo docker_version=develop >> $GITHUB_ENV
echo version=develop >> $GITHUB_ENV
fi
echo plugin_file=`cat ./${{ matrix.plugin }}/plugin.json` >> $GITHUB_ENV
- name: Check if Dockerfile exists
id: check_dockerfile
uses: andstor/file-existence-action@v3
with:
files: "${{ matrix.plugin }}/task/Dockerfile"
- name: Set up QEMU
if: ${{ steps.check_dockerfile.outputs.files_exists == 'true' }}
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: ${{ steps.check_dockerfile.outputs.files_exists == 'true' }}
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: ${{ steps.check_dockerfile.outputs.files_exists == 'true' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub container Registry
if: ${{ steps.check_dockerfile.outputs.files_exists == 'true' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
if: ${{ steps.check_dockerfile.outputs.files_exists == 'true' }}
uses: docker/build-push-action@v5
with:
context: ${{ matrix.plugin }}/task
push: true
tags: |
thinger/${{ matrix.plugin }}-plugin:${{ env.docker_version }}
- name: Update README in DockerHub
if: ${{ steps.check_dockerfile.outputs.files_exists == 'true' && env.branch == 'main' }}
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: thinger/${{ matrix.plugin }}-plugin
readme-filepath: ./${{ matrix.plugin }}/README.md
- name: Delete tag of repository
if: ${{ startsWith(env.branch, 'develop') }}
uses: dev-drprasad/[email protected]
with:
tag_name: ${{ matrix.plugin }}/${{ env.version }}
github_token: ${{ secrets.GITHUB_TOKEN }}
delete_release: false
- name: Tag repository
uses: mathieudutour/[email protected]
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ matrix.plugin }}/${{ env.version }}
tag_prefix: ''
- name: Post tag to DB
uses: fjogeleit/http-request-action@v1
with:
url: "https://cloud.thinger.io/plugins/${{ matrix.plugin }}/tags/${{ env.version }}"
method: 'PUT'
username: ${{ secrets.LAMBDA_USER }}
password: ${{ secrets.LAMBDA_PASSWORD }}
timeout: 30000 # 30s
customHeaders: '{"Content-Type": "application/json"}'
data: |
{
"plugin": "${{ matrix.plugin }}",
"version": "${{ env.version }}",
"commit": "${{ github.sha }}",
"repository": "${{ github.repository }}",
"server_url": "${{ github.server_url }}",
"plugin_file": ${{ env.plugin_file }}
}