-
Notifications
You must be signed in to change notification settings - Fork 33
202 lines (186 loc) · 7.46 KB
/
version.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
name: VersionReplace
on:
pull_request:
paths:
- 'FHEM/**'
- '.github/workflows/version.yml'
jobs:
pre_ci:
name: Prepare CI environment
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@v4
with:
# We need to fetch with a depth of 2 for pull_request so we can do HEAD^2
fetch-depth: 2
# If this workflow was triggered by a push then resolve the commit message from HEAD
# It is stored in output steps, to be referenced with ${{ steps.push_get_commit_message.outputs.push_commit_message }}
- name: "[Push] Get commit message"
if: github.event_name == 'push'
id: push_get_commit_message
run: |
{
echo 'pr_commit_message<<EOF'
git log --format=%B -n 1 HEAD
echo EOF
} >> $GITHUB_OUTPUT
# If this workflow was triggered by a pull request (open or synchronize!) then resolve the commit message from HEAD^2
# It is stored in output steps, to be referenced with ${{ steps.pr_get_commit_message.outputs.pr_commit_message }}
- name: "[Pull Request] Get commit message"
if: github.event_name == 'pull_request'
id: pr_get_commit_message
run: |
{
echo 'pr_commit_message<<EOF'
git log --format=%B -n 1 HEAD^2
echo EOF
} >> $GITHUB_OUTPUT
# Finally we want to make the commit message available to other jobs. This can be done with job-level outputs
# However as we do not know whether the commit message was set in Push or Pull Request event we need to do some
# bash magic to resolve the one or the other
#
# For **Pull Request** events this will resolve to something like "$( [ -z "commit message pr" ] && echo "" || echo "commit message pr" )" which then resolves to just "commit message pr"
#
# For **Push** events this will resolve to something like "$( [ -z "" ] && echo "commit message push" || echo "" )" which then resolves to just "commit message push"
outputs:
commit_message: $( [ -z "${{ steps.pr_get_commit_message.outputs.pr_commit_message }}" ] && echo "${{ steps.push_get_commit_message.outputs.push_commit_message }}" || echo "${{ steps.pr_get_commit_message.outputs.pr_commit_message }}" )
metadata:
# Do not run this job again if the last commit was a Update Versondate which comes from this workflow!
if: "!contains(needs.pre_ci.outputs.commit_message, 'Update Versiondate')"
needs: pre_ci
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
date: ${{ steps.date.outputs.date }}
datetime: ${{ steps.date.outputs.datetimestr }}
runs-on: ubuntu-latest
steps:
- id: file_changes
uses: tj-actions/changed-files@v44
with:
json: true
quotepath: false
files: |
FHEM/**.pm
FHEM/lib/**.pm
lib/FHEM/**.pm
- name: Get current date
id: date
run: |
echo "date=$(date -u +'%Y%m%d')" >> $GITHUB_OUTPUT
echo "datetimestr=$(date -u +'%Y-%m-%d %T')" >> $GITHUB_OUTPUT
- name: Set matrix for build
id: set-matrix
if: ${{ github.event.sender != 'actions-user' }}
run:
echo "matrix={\"files\":${{ steps.file_changes.outputs.all_changed_files }}}" >> "$GITHUB_OUTPUT"
modify:
if: ${{ fromJSON( needs.metadata.outputs.matrix ).files[0] }}
continue-on-error: true
runs-on: ubuntu-latest
needs: metadata
strategy:
matrix: ${{ fromJson(needs.metadata.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Find Version String
if: endsWith(matrix.files, '00_SIGNALduino.pm')
id: versionList
uses: nguyenvanuyn96/str-find-action@master
with:
find: '\d\.\d\.\d'
include: "${{ matrix.files }}"
- uses: jungwinter/split@v2
name: Split array result
if: ${{ steps.versionList.outputs.fileFoundCount > 0 }}
id: versions
with:
msg: '${{ steps.versionList.outputs.resultArray }}'
separator: ' '
- name: Update SDUINO_VERSION date
if: endsWith(matrix.file, '00_SIGNALduino.pm')
uses: jacobtomlinson/gha-find-replace@v3.0.4
with:
find: \w+\s+=>\s\'\d.\d.\d\+\d+\'
replace: "SDUINO_VERSION => '${{ steps.versions.outputs._1 }}+${{ needs.metadata.outputs.date }}'"
include: "${{ matrix.files }}"
- name: Update Date in ID line
uses: jacobtomlinson/gha-find-replace@v3.0.4
with:
find: \d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\dZ\s[\w|-]+\s
replace: "${{ needs.metadata.outputs.datetime }}Z ${{ github.event.pull_request.user.login }} "
include: "${{ matrix.files }}"
- name: Artifactname
env:
ARTIFACT_NAME: "${{ matrix.files }}"
run: |
ARTIFACT_NAME=${{ env.ARTIFACT_NAME }}
ARTIFACT_NAME=$(basename $ARTIFACT_NAME) # get only the filename and use this as artifact name
echo ARTIFACT_NAME=${ARTIFACT_NAME} >> $GITHUB_ENV # update GitHub ENV vars
- name: Save updated Files in artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
retention-days: 1
path: |
${{ matrix.files }}
commit:
permissions:
contents: write
runs-on: ubuntu-latest
needs: modify
name: Commit and Push back
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false
- name: Download all modified artifacts
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/artifacts
- name: replace files from artifacts
run: |
for FPATH in ./artifacts/*/*.pm; do
FILE=$(basename $FPATH)
find ./FHEM -name "$FILE" -exec cp $FPATH "{}" \;
done
- name: update controls file (FHEM)
uses: fhem/fhem-controls-actions@v2.3.0
with:
filename: controls_signalduino.txt
- name: update controls file (lib)
uses: fhem/fhem-controls-actions@v2.3.0
with:
filename: controls_signalduino.txt
directory: FHEM/lib
writemode: a
- name: git commit back
id: commit
run: |
git config --global user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit -m "Update Versiondate" -a && echo "status=true" >> $GITHUB_OUTPUT || true
- name: Wait for tests to succeed
if: ${{ steps.commit.outputs.status }}
uses: lewagon/wait-on-check-action@v1.3.4
with:
running-workflow-name: 'Commit and Push back'
ref: ${{ github.head_ref }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 20
allowed-conclusions: success,skipped,cancelled,neutral
ignore-checks: codecov/patch
- name: git push
if: ${{ steps.commit.outputs.status }}
uses: ad-m/github-push-action@v0.8.0
with:
github_token: ${{ secrets.GH_TOKEN }}
branch: ${{ github.head_ref }}
#- name: Push to branch
# uses: CasperWA/push-protected@v2
# with:
# token: ${{ secrets.GH_TOKEN }}
# branch: ${{ github.head_ref }}
# #unprotect_reviews: true