Skip to content

Commit 3619040

Browse files
authored
Trigger OTP prebuilt workflow on every new release (#11)
1 parent a69afd7 commit 3619040

File tree

2 files changed

+204
-0
lines changed

2 files changed

+204
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: On Grisp Crypto Auth Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
trigger-otp-build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Trigger OTP package build
12+
run: |
13+
curl -s https://raw.githubusercontent.com/erlang/otp/master/otp_versions.table \
14+
| grep '^OTP-' \
15+
| cut -d' ' -f1 \
16+
| sed 's/OTP-//' \
17+
| sort -V \
18+
| awk -F. '{
19+
major_version = $1;
20+
latest[major_version] = $0;
21+
}
22+
END {
23+
for (m in latest) print latest[m];
24+
}' \
25+
| sort -Vr \
26+
| head -n 4 \
27+
| while read OTP_VER; do
28+
echo "Triggering for OTP: $OTP_VER"
29+
curl -L -X POST \
30+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
31+
-H "Accept: application/vnd.github.everest-preview+json" \
32+
https://api.github.com/repos/grisp/grisp_cryptoauth/dispatches \
33+
-d "{\"event_type\":\"grispcryptoauth-release\",\"client_payload\":{\"otp\":\"\\\\\\\"${OTP_VER}\\\\\\\"\",\"unit\":false,\"integration\":true}}"
34+
done

.github/workflows/otp-package.yaml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: OTP Package on new Grisp Release
2+
3+
on:
4+
repository_dispatch:
5+
types:
6+
- grispcryptoauth-release
7+
8+
jobs:
9+
define-matrix:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
otp-version: ${{ steps.matrix-def.outputs.otp-version }}
13+
steps:
14+
- name: Matrix Definition
15+
id: matrix-def
16+
run: |
17+
echo "otp-version=${{ github.event.client_payload.otp }}" >> "$GITHUB_OUTPUT"
18+
otp-gen-matrix:
19+
runs-on: ubuntu-latest
20+
needs: define-matrix
21+
container:
22+
# This image is based on debian:bookworm
23+
# but we need to make erlef/setup-beam@v1 happy
24+
# so we set 'ubuntu22' (jammy), which is the most similar, as ImageOS
25+
image: grisp/grisp2-rtems-toolchain
26+
env:
27+
ImageOS: 'ubuntu22'
28+
strategy:
29+
matrix:
30+
otp: ["${{ fromJson(needs.define-matrix.outputs.otp-version) }}"]
31+
deps: ['grisp, grisp_cryptoauth']
32+
rebar3: ['3.24.0']
33+
fail-fast: false
34+
outputs:
35+
report: ${{ steps.report.outputs.report }}
36+
steps:
37+
- uses: erlef/setup-beam@v1
38+
with:
39+
otp-version: ${{matrix.otp}}
40+
rebar3-version: ${{ matrix.rebar3 }}
41+
- name: Install GRiSP Plugin
42+
run: |
43+
mkdir -p ${HOME}/.config/rebar3/
44+
echo "{plugins, [rebar3_hex,rebar3_grisp]}." > ${HOME}/.config/rebar3/rebar.config
45+
rebar3 update
46+
- name: Generate Dummy Project
47+
run: |
48+
rebar3 grisp configure -i false --otp_version="=${{matrix.otp}}" --dest="_deploy"
49+
mkdir robot/_deploy
50+
sed -i 's/grisp/${{matrix.deps}}/g' robot/src/robot.app.src
51+
sed -i '/{deps, \[/,/\]}.*/{
52+
N
53+
N
54+
s/{deps, \[\n[[:space:]]*grisp\n\]}.*/{deps, [${{matrix.deps}}]}./
55+
}' robot/rebar.config
56+
cat robot/rebar.config
57+
- name: Try to Deploy
58+
id: deploy
59+
continue-on-error: true
60+
working-directory: robot
61+
run: |
62+
rebar3 grisp deploy
63+
- name: Build OTP
64+
id: build
65+
if: ${{ steps.deploy.outcome == 'failure' }}
66+
working-directory: robot
67+
continue-on-error: true
68+
run: |
69+
sed -i '/{grisp, \[/a\
70+
'"{build, [{toolchain, [{directory, \"/grisp2-rtems-toolchain\"}]}]}," rebar.config
71+
cat rebar.config
72+
rebar3 grisp build --tar
73+
PKG_NAME=$(ls _grisp/grisp2/otp/${{matrix.otp}}/package)
74+
echo "pkg_name=$PKG_NAME" >> $GITHUB_ENV
75+
- name: Create GitHub Issue
76+
if: ${{ steps.build.outcome == 'failure' }}
77+
run: |
78+
apt-get update && apt-get install -y curl
79+
curl -L -X POST \
80+
-H "Accept: application/vnd.github+json" \
81+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
82+
-H "X-GitHub-Api-Version: 2022-11-28" \
83+
https://api.github.com/repos/grisp/grisp_cryptoauth/issues \
84+
-d '{"title":"Failed package build for OTP-${{matrix.otp}}","body":"Prebuilt package build failed:\n OTP Version: ${{matrix.otp}}\n Applications: [${{matrix.deps}}]\nWorkflow Run: https://github.com/grisp/grisp_cryptoauth/actions/runs/${{github.run_id}}", "labels":["otp-build"]}'
85+
exit 1
86+
- name: Deploy test
87+
if: ${{ steps.build.outcome == 'success' }}
88+
id: deploy-test
89+
working-directory: robot
90+
run: |
91+
rebar3 grisp deploy
92+
- name: Upload as GitHub Artifact
93+
id: artifact-upload
94+
if: ${{ steps.deploy-test.outcome == 'success' }}
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: ${{env.pkg_name}}
98+
path: robot/_grisp/grisp2/otp/${{matrix.otp}}/package/${{env.pkg_name}}
99+
upload_artifacts:
100+
runs-on: ubuntu-latest
101+
needs: [define-matrix, otp-gen-matrix]
102+
strategy:
103+
matrix:
104+
otp: ["${{ fromJson(needs.define-matrix.outputs.otp-version) }}"]
105+
deps: ['grisp, grisp_cryptoauth']
106+
rebar3: ['3.24.0']
107+
outputs:
108+
artifacts: ${{ steps.matrix-def.outputs.otp-version }}
109+
upload-output: ${{ steps.set-upload-output.outputs.upload-output }}
110+
steps:
111+
- uses: erlef/setup-beam@v1
112+
with:
113+
otp-version: ${{matrix.otp}}
114+
rebar3-version: ${{ matrix.rebar3 }}
115+
- name: Install GRiSP Plugin
116+
run: |
117+
mkdir -p ${HOME}/.config/rebar3/
118+
echo "{plugins, [rebar3_hex,rebar3_grisp]}." > ${HOME}/.config/rebar3/rebar.config
119+
rebar3
120+
- name: Generate Dummy Project
121+
run: |
122+
rebar3 grisp configure -i false --otp_version="=${{matrix.otp}}" --dest="_deploy"
123+
mkdir robot/_deploy
124+
sed -i 's/grisp/${{matrix.deps}}/g' robot/src/robot.app.src
125+
sed -i '/{deps, \[/,/\]}.*/{
126+
N
127+
N
128+
s/{deps, \[\n[[:space:]]*grisp\n\]}.*/{deps, [${{matrix.deps}}]}./
129+
}' robot/rebar.config
130+
cat robot/rebar.config
131+
- name: Build Package
132+
id: deploy
133+
working-directory: robot
134+
run: |
135+
sed -i '/{grisp, \[/a\
136+
'"{build, []}," rebar.config
137+
rebar3 grisp report
138+
PKG_HASH=$(grep -o '<<"[0-9a-f]\{64\}">>' _grisp/report/hash.txt | tail -n 1 | sed 's/[<">]//g')
139+
PKG_NAME=grisp_otp_build_${{matrix.otp}}_${PKG_HASH}.tar.gz
140+
echo "pkg_name=$PKG_NAME" >> $GITHUB_ENV
141+
- name: Download Package Artifact
142+
id: artifact-download
143+
uses: actions/download-artifact@v4
144+
continue-on-error: true
145+
with:
146+
name: ${{env.pkg_name}}
147+
- name: Download from S3 if artifact not found
148+
id: download-s3
149+
if: steps.artifact-download.outcome == 'failure'
150+
env:
151+
AWS_ACCESS_KEY_ID: ${{ secrets.GRISP_S3_ACCESS_KEY_ID }}
152+
AWS_SECRET_ACCESS_KEY: ${{ secrets.GRISP_S3_SECRET_ACCESS_KEY }}
153+
AWS_DEFAULT_REGION: "us-east-1"
154+
run: |
155+
aws s3 cp s3://grisp/platforms/grisp2/otp/${{env.pkg_name}} .
156+
- name: Upload to S3
157+
id: upload-s3
158+
if: ${{ steps.artifact-download.outcome == 'success' }}
159+
env:
160+
AWS_ACCESS_KEY_ID: ${{ secrets.GRISP_S3_ACCESS_KEY_ID }}
161+
AWS_SECRET_ACCESS_KEY: ${{ secrets.GRISP_S3_SECRET_ACCESS_KEY }}
162+
AWS_DEFAULT_REGION: "us-east-1"
163+
run: |
164+
aws s3 cp --acl public-read --storage-class INTELLIGENT_TIERING \
165+
${{env.pkg_name}} \
166+
s3://grisp/platforms/grisp2/otp/
167+
- name: Set S3 upload output
168+
if: ${{ steps.upload-s3.outcome == 'success' }}
169+
run: echo "upload-output=true" >> $GITHUB_OUTPUT
170+
id: set-upload-output

0 commit comments

Comments
 (0)