-
Notifications
You must be signed in to change notification settings - Fork 5
185 lines (169 loc) · 8.84 KB
/
checkandgenerate.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
name: "KiCad ERC/DRC Check and Outputs generation"
on:
workflow_dispatch:
push:
branches: [main, develop]
jobs:
drcerc:
name: Run DRC and ERC, Export Schematic as PDF
permissions: write-all
runs-on: ubuntu-latest
outputs:
branchname: ${{ steps.versioninfo.outputs.branchname }}
commithash: ${{ steps.versioninfo.outputs.commithash }}
buildtimestamp: ${{ steps.versioninfo.outputs.buildtimestamp }}
buildtimestampshort: ${{ steps.versioninfo.outputs.buildtimestampshort }}
lastmajordigit: ${{ steps.versioninfo.outputs.lastmajordigit }}
lastminordigit: ${{ steps.versioninfo.outputs.lastminordigit }}
lastpatchdigit: ${{ steps.versioninfo.outputs.lastpatchdigit }}
lastversion: ${{ steps.versioninfo.outputs.lastversion }}
nextmajordigit: ${{ steps.selectversion.outputs.nextmajordigit }}
nextminordigit: ${{ steps.selectversion.outputs.nextminordigit }}
nextpatchdigit: ${{ steps.selectversion.outputs.nextpatchdigit }}
buildversion: ${{ steps.selectversion.outputs.buildversion }}
env:
CI_COMMIT_MESSAGE: add workflow generated files
CI_COMMIT_AUTHOR: CD Workflow
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version data
id: versioninfo
run: |
echo "extract branch name from github_ref '${{ github.ref }}'"
declare branchname=$(echo "${{ github.ref }}" | cut -d'/' -f 3-)
echo "clean branch name = $branchname"
echo "extract commit short hash : $(git rev-parse --short HEAD)"
declare commithash=$(git rev-parse --short HEAD)
echo "extract build timestamp"
declare buildtimestamp=$(date +"%a %b %d %H:%M:%S %Y")
echo "buildtimestamp = $buildtimestamp"
declare buildtimestampshort=$(date +"%d %b %y")
declare fulltag=$(git describe --tag $(git rev-parse --verify refs/remotes/origin/main))
echo "fulltag = [$fulltag]"
declare versiontag=$(echo $fulltag | cut -d'-' -f1)
echo "extract SemVer numbers from version tag [$versiontag]"
declare -i lastmajordigit=$(echo $versiontag | cut -c 2- | cut -d'.' -f1)
echo "lastmajordigit = $lastmajordigit"
declare -i lastminordigit=$(echo $versiontag | cut -c 2- | cut -d'.' -f2)
echo "lastminordigit = $lastminordigit"
declare lastversion="v$lastmajordigit.$lastminordigit"
echo "output variables to GitHub Actions"
echo "branchname=$branchname" >> $GITHUB_OUTPUT
echo "lastmajordigit=$lastmajordigit" >> $GITHUB_OUTPUT
echo "lastminordigit=$lastminordigit" >> $GITHUB_OUTPUT
echo "commithash=$commithash" >> $GITHUB_OUTPUT
echo "buildtimestamp=$buildtimestamp" >> $GITHUB_OUTPUT
echo "buildtimestampshort=$buildtimestampshort" >> $GITHUB_OUTPUT
echo "lastversion=$lastversion" >> $GITHUB_OUTPUT
- name: Determine which version to build
id: selectversion
run: |
echo "Triggered from Branch : ${{ steps.versioninfo.outputs.branchname }}"
echo "Commit hash : ${{ steps.versioninfo.outputs.commithash }}"
echo "Last version : ${{ steps.versioninfo.outputs.lastversion }}"
echo " Major : ${{ steps.versioninfo.outputs.lastmajordigit }}"
echo " Minor : ${{ steps.versioninfo.outputs.lastminordigit }}"
if [ "${{ steps.versioninfo.outputs.branchname }}" == "main" ]; then
echo "Triggered from merge on main branch with commit title : ${{ github.event.head_commit.message }}"
if [[ "${{ github.event.head_commit.message }}" == *"major"* ]]; then
echo "Incrementing Major versionDigit"
declare -i nextmajordigit=${{ steps.versioninfo.outputs.lastmajordigit }}+1
declare -i nextminordigit=0
declare buildversion="v$nextmajordigit.$nextminordigit"
else
echo "Incrementing Minor versionDigit"
declare -i nextmajordigit=${{ steps.versioninfo.outputs.lastmajordigit }}
declare -i nextminordigit=${{ steps.versioninfo.outputs.lastminordigit }}+1
declare buildversion="v$nextmajordigit.$nextminordigit"
fi
else
echo "Not on main branch -> development version"
declare -i nextmajordigit=${{ steps.versioninfo.outputs.lastmajordigit }}
declare -i nextminordigit=${{ steps.versioninfo.outputs.lastminordigit }}
declare buildversion="v$nextmajordigit.$nextminordigit-${{ steps.versioninfo.outputs.commithash }}"
fi
echo "Building Version : $buildversion"
echo " Major : $nextmajordigit"
echo " Minor : $nextminordigit"
echo "output variables to GitHub Actions"
echo "nextmajordigit=$nextmajordigit" >> $GITHUB_OUTPUT
echo "nextminordigit=$nextminordigit" >> $GITHUB_OUTPUT
echo "buildversion=$buildversion" >> $GITHUB_OUTPUT
- name: Show Build info
id: showbuildinfo
run: |
echo "Build Version : ${{ steps.selectversion.outputs.buildversion }}"
echo " Major : ${{ steps.selectversion.outputs.nextmajordigit }}"
echo " Minor : ${{ steps.selectversion.outputs.nextminordigit }}"
echo "Build Timestamp : ${{ steps.versioninfo.outputs.buildtimestamp }}"
echo "Build Timestamp Short : ${{ steps.versioninfo.outputs.buildtimestampshort }}"
# - name: Save Build info
# uses: "DamianReeves/write-file-action@master"
# with:
# path: .github/kibot/version.yaml
# write-mode: overwrite
# contents: |
# # ##########################################################################
# # ### This file is generated by Build and Continuous Integration script ###
# # ### .github/workflows/checkandgenerate.yml for CI environment ###
# # ### Changes will be overwritten on the next workflow run ###
# # ##########################################################################
# definitions:
# majorVersionDigit: ${{ steps.selectversion.outputs.nextmajordigit }}
# minorVersionDigit: ${{ steps.selectversion.outputs.nextminordigit }}
# lastCommitTag: "${{ steps.versioninfo.outputs.commithash }}"
# buildTimeStamp: "${{ steps.versioninfo.outputs.buildtimestamp }}"
# - name: Verify Saved Build info
# run: |
# cat .github/kibot/version.yaml
- name: Save info in environment variables
run: |
echo "MAJORVERSIONDIGIT=${{ steps.selectversion.outputs.nextmajordigit }}" >> $GITHUB_ENV
echo "MINORVERSIONDIGIT=${{ steps.selectversion.outputs.nextminordigit }}" >> $GITHUB_ENV
echo "BUILDTIMESTAMP=${{ steps.versioninfo.outputs.buildtimestamp }}" >> $GITHUB_ENV
echo "BUILDTIMESTAMPSHORT=${{ steps.versioninfo.outputs.buildtimestampshort }}" >> $GITHUB_ENV
- name: Verify environment variables
run: |
echo $MAJORVERSIONDIGIT
echo $MINORVERSIONDIGIT
echo $BUILDTIMESTAMP
echo $BUILDTIMESTAMPSHORT
- name: run KiBOT
uses: INTI-CMNB/KiBot@v2_dk8
# uses: INTI-CMNB/KiBot@v2_k8 : v2_k8 = stable release, v2_dk8 is dev version
with:
# additional_args: '--verbose'
config: .github/kibot/main.kibot.yaml
dir: outputs
- name: GIT Commit CI Artifacts
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "[email protected]"
git add .
git commit -a -m "${{ env.CI_COMMIT_MESSAGE }}"
git push
- name: Release when on main branch
id: createrelease
uses: actions/create-release@v1
if: ${{ steps.versioninfo.outputs.branchname == 'main'}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.selectversion.outputs.buildversion }}
release_name: Release ${{ steps.selectversion.outputs.buildversion }}
draft: false
prerelease: false
# - name: Attach Binary to Release
# id: attachbinarytorelease
# uses: actions/upload-release-asset@v1
# if: ${{ steps.versioninfo.outputs.branchname == 'main'}}
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.createrelease.outputs.upload_url }}
# asset_path: .pio/build/production/firmware.bin
# asset_name: ${{ steps.selectversion.outputs.buildversionfilename }}.bin
# asset_content_type: application/octet-stream