generated from circuitdojo/zephyr-template
-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (136 loc) · 6.09 KB
/
release.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
name: Release
on:
workflow_dispatch:
inputs:
version_tag:
description: 'Version tag'
required: true
type: string
workflow_call:
inputs:
version_tag:
description: 'Version tag'
required: true
type: string
jobs:
build:
uses: ./.github/workflows/build.yml
with:
release_build: true
secrets: inherit
release:
needs: build
runs-on: ubuntu-latest
env:
version_tag: ${{ inputs.version_tag }}
steps:
- name: Check for curl
run: type -p curl >/dev/null || (sudo apt-get update && sudo apt-get install curl -y)
- name: Extract branch name
shell: bash
run: echo "BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV
- name: Check for existing release
id: check_release
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
run: |
curl -L -X GET \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${{ env.OWNER }}/${{ env.REPO }}/releases/tags/${{ env.version_tag }}" \
-o release.json
# Don't return exit code 1 if no match found
# Credit https://stackoverflow.com/a/49627999/8120300
html_url=$({ grep -Po -m 1 '(?:\G(?!^)",|"html_url":\s*)\s*"\K[^"]+' release.json || test $? = 1; }| { grep -v grep || test $? = 1; })
if [[ -z "$html_url" ]]; then
echo "No release matching tag ${{ env.version_tag }} found" >> $GITHUB_STEP_SUMMARY
echo "needs_release=true" >> $GITHUB_OUTPUT
else
echo "upload_url=$(grep -Po '(?:\G(?!^)",|"upload_url":\s*)\s*"\K[^"{]+' release.json)" >> $GITHUB_ENV
echo "Found release [${{ env.version_tag }}]($html_url)" >> $GITHUB_STEP_SUMMARY
fi
- name: Create release
if: ${{ steps.check_release.outputs.needs_release }}
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
BRANCH: main
run: |
curl -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${{ env.OWNER }}/${{ env.REPO }}/releases" \
-d '{"tag_name":"${{ env.version_tag }}","target_commitish":"${{ env.BRANCH }}","body":"___This release was automatically generated when the app version increased___","draft":false,"prerelease":false,"generate_release_notes":true}' \
-o release.json
echo "upload_url=$(grep -Po '(?:\G(?!^)",|"upload_url":\s*)\s*"\K[^"{]+' release.json)" >> $GITHUB_ENV
html_url=$(grep -Po -m 1 '(?:\G(?!^)",|"html_url":\s*)\s*"\K[^"]+' release.json)
echo "Created release [${{ env.version_tag }}]($html_url)" >> $GITHUB_STEP_SUMMARY
- name: Download artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Upload merged.hex
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
run: |
curl -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"${{ env.upload_url }}?name=${{ env.BRANCH }}_merged.hex" \
--data-binary "@merged.hex"
echo 'Uploaded build artifact ${{ env.BRANCH }}_merged.hex as asset to release' >> $GITHUB_STEP_SUMMARY
- name: Upload merged_sha256.sum
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
run: |
sha256sum merged.hex > merged_sha256.sum
curl -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"${{ env.upload_url }}?name=${{ env.BRANCH }}_merged_sha256.sum" \
--data-binary "@merged_sha256.sum"
echo 'Uploaded build artifact ${{ env.BRANCH }}_merged_sha256.sum as asset to release' >> $GITHUB_STEP_SUMMARY
- name: Upload zephyr.signed.bin
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
run: |
curl -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"${{ env.upload_url }}?name=${{ env.BRANCH }}_zephyr.signed.bin" \
--data-binary "@zephyr.signed.bin"
echo 'Uploaded build artifact ${{ env.BRANCH }}_zephyr.signed.bin as asset to release' >> $GITHUB_STEP_SUMMARY
- name: Upload zephyr_signed_bin_sha256.sum
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
run: |
sha256sum zephyr.signed.bin > zephyr_signed_bin_sha256.sum
curl -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"${{ env.upload_url }}?name=${{ env.BRANCH }}_zephyr_signed_bin_sha256.sum" \
--data-binary "@zephyr_signed_bin_sha256.sum"
echo 'Uploaded build artifact ${{ env.BRANCH }}_zephyr_signed_bin_sha256.sum as asset to release' >> $GITHUB_STEP_SUMMARY