Skip to content

Commit 7859ca4

Browse files
committed
feat: Updated gh build worklow to build btc only app
1 parent 54bf3b4 commit 7859ca4

File tree

2 files changed

+102
-37
lines changed

2 files changed

+102
-37
lines changed

.github/workflows/build.yml

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,98 @@ jobs:
1515
matrix:
1616
firmware: [Main]
1717
target: [Release]
18-
coin_support: ["BTC_ONLY", "MULTI_COIN"]
18+
coin_support: ["BTC_ONLY", "MULTI_COIN"] # Builds both BTC_ONLY and MULTI_COIN variants
1919
uses: ./.github/workflows/containerized-build.yml
2020
with:
2121
firmware: ${{ matrix.firmware }}
2222
target: ${{ matrix.target }}
2323
coin_support_variant: ${{ matrix.coin_support }}
2424
secrets: inherit
25+
2526
create-release:
26-
needs: build-firmwares
27+
needs: build-firmwares # Depends on all firmwares being built
2728
runs-on: ubuntu-latest
2829
if: ${{ github.ref_type }} == 'tag'
2930
steps:
3031
- name: Checkout
3132
uses: actions/checkout@v3
33+
3234
- name: Download artifacts
3335
uses: actions/download-artifact@v4
3436
with:
35-
path: ./
37+
path: ./ # Downloads all artifacts to the current directory
38+
3639
- name: Publish a release
3740
env:
3841
TAG_NAME: ${{ github.ref_name }}
3942
auth_token: ${{ secrets.GITHUB_TOKEN }}
4043
REPOSITORY: ${{ github.repository }}
4144
run: |
42-
chkmain=$(sha256sum Main-Release-outputs/Cypherock-Main.bin | cut -f -1 -d ' ')
45+
# Calculate SHA256 hash for the MULTI_COIN firmware
46+
# The path assumes download-artifact placed it in Main-Release-MULTI_COIN-outputs/build/
47+
chkmain_multicoin=$(sha256sum Main-Release-MULTI_COIN-outputs/build/Cypherock-Main.bin | cut -f -1 -d ' ')
48+
49+
# Calculate SHA256 hash for the BTC_ONLY firmware
50+
# The path assumes download-artifact placed it in Main-Release-BTC_ONLY-outputs/build/
51+
# The filename is Cypherock-Main-btc.bin due to the CMakeLists.txt modification
52+
chkmain_btc_only=$(sha256sum Main-Release-BTC_ONLY-outputs/build/Cypherock-Main-btc.bin | cut -f -1 -d ' ')
53+
4354
APP_VERSION=$(cat version.txt | grep firmware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }')
4455
HW_VERSION=$(cat version.txt | grep hardware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }')
45-
echo ${APP_VERSION}:${HW_VERSION}
46-
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${REPOSITORY}/releases -d '{"tag_name":"'${TAG_NAME}'","target_commitish":"main","name":"'${TAG_NAME}'","body":"Application version: '${APP_VERSION}'\r\nHardware version: '${HW_VERSION}'\r\n## SHA256 of binaries:\r\n**Cypherock-Main.bin** : '${chkmain}'","draft":true,"prerelease":false,"generate_release_notes":true}' > output.txt
56+
57+
echo "Application version: ${APP_VERSION}"
58+
echo "Hardware version: ${HW_VERSION}"
59+
60+
# Create the release with both firmware hashes in the body
61+
curl -X POST \
62+
-H "Accept: application/vnd.github+json" \
63+
-H "Authorization: Bearer ${auth_token}" \
64+
-H "X-GitHub-Api-Version: 2022-11-28" \
65+
https://api.github.com/repos/${REPOSITORY}/releases \
66+
-d '{
67+
"tag_name":"'${TAG_NAME}'",
68+
"target_commitish":"main",
69+
"name":"'${TAG_NAME}'",
70+
"body":"Application version: '${APP_VERSION}'\r\nHardware version: '${HW_VERSION}'\r\n## SHA256 of binaries:\r\n**Cypherock-Main.bin** : '${chkmain_multicoin}' \r\n**Cypherock-Main-btc.bin** : '${chkmain_btc_only}'",
71+
"draft":true,
72+
"prerelease":false,
73+
"generate_release_notes":true
74+
}' > output.txt
75+
76+
# Extract upload_url for subsequent asset uploads
4777
echo "upload_url=$(cat output.txt | grep "\"upload_url\":" | cut -f 4-4 -d '"' | cut -f 1-1 -d '{')" >> $GITHUB_ENV
78+
4879
- name: Upload assets
4980
env:
5081
auth_token: ${{ secrets.GITHUB_TOKEN }}
82+
upload_url: ${{ env.upload_url }} # Use the extracted upload_url
5183
run: |
52-
content_type=$(file -b --mime-type Main-Release-outputs/Cypherock-Main.bin)
53-
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=Cypherock-Main.bin --data-binary @Main-Release-outputs/Cypherock-Main.bin
54-
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=version.txt --data-binary @version.txt
84+
# Upload the MULTI_COIN firmware binary
85+
content_type_multicoin=$(file -b --mime-type Main-Release-MULTI_COIN-outputs/build/Cypherock-Main.bin)
86+
curl -X POST \
87+
-H "Content-Type: ${content_type_multicoin}" \
88+
-H "Accept: application/vnd.github+json" \
89+
-H "Authorization: Bearer ${auth_token}" \
90+
-H "X-GitHub-Api-Version: 2022-11-28" \
91+
"${upload_url}?name=Cypherock-Main.bin" \
92+
--data-binary @Main-Release-MULTI_COIN-outputs/build/Cypherock-Main.bin
93+
94+
# Upload the BTC_ONLY firmware binary
95+
content_type_btc_only=$(file -b --mime-type Main-Release-BTC_ONLY-outputs/build/Cypherock-Main-btc.bin)
96+
curl -X POST \
97+
-H "Content-Type: ${content_type_btc_only}" \
98+
-H "Accept: application/vnd.github+json" \
99+
-H "Authorization: Bearer ${auth_token}" \
100+
-H "X-GitHub-Api-Version: 2022-11-28" \
101+
"${upload_url}?name=Cypherock-Main-btc.bin" \
102+
--data-binary @Main-Release-BTC_ONLY-outputs/build/Cypherock-Main-btc.bin
103+
104+
# Upload version.txt
105+
content_type_version=$(file -b --mime-type version.txt)
106+
curl -X POST \
107+
-H "Content-Type: ${content_type_version}" \
108+
-H "Accept: application/vnd.github+json" \
109+
-H "Authorization: Bearer ${auth_token}" \
110+
-H "X-GitHub-Api-Version: 2022-11-28" \
111+
"${upload_url}?name=version.txt" \
112+
--data-binary @version.txt

CMakeLists.txt

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ else()
1313
set(PROJECT Cypherock_Simulator)
1414
endif()
1515

16+
# Define all options upfront, including BTC_ONLY
17+
OPTION(DEV_SWITCH "Additional features/logs to aid developers" OFF)
18+
OPTION(UNIT_TESTS_SWITCH "Compile build for main firmware or unit tests" OFF)
19+
OPTION(BTC_ONLY "Build firmware for Bitcoin only" OFF)
20+
21+
# Logic to append -btc to project name if BTC_ONLY is enabled
22+
if (BTC_ONLY)
23+
set(PROJECT ${PROJECT}-btc)
24+
endif()
25+
26+
# Make static functions testable via unit-tests
27+
IF(UNIT_TESTS_SWITCH)
28+
add_compile_definitions( STATIC= )
29+
ELSE()
30+
add_compile_definitions( STATIC=static )
31+
ENDIF(UNIT_TESTS_SWITCH)
32+
33+
# Now define the project with its final name, after all modifications
1634
project(${PROJECT})
1735

1836
# python is needed for compiling proto files using nanopb
@@ -24,37 +42,26 @@ execute_process(COMMAND sh utilities/proto/generate-protob.sh WORKING_DIRECTORY
2442
include(utilities/cmake/version.cmake)
2543

2644
file(GLOB_RECURSE PROTO_SRCS "generated/proto/*.*")
27-
list(APPEND PROTO_SRCS
28-
"vendor/nanopb/pb_common.c"
29-
"vendor/nanopb/pb_decode.c"
30-
"vendor/nanopb/pb_encode.c"
31-
"vendor/nanopb/pb_common.h"
32-
"vendor/nanopb/pb_decode.h"
33-
"vendor/nanopb/pb_encode.h"
45+
list(APPEND PROTO_SRCS
46+
"vendor/nanopb/pb_common.c"
47+
"vendor/nanopb/pb_decode.c"
48+
"vendor/nanopb/pb_encode.c"
49+
"vendor/nanopb/pb_common.h"
50+
"vendor/nanopb/pb_decode.h"
51+
"vendor/nanopb/pb_encode.h"
3452
"vendor/nanopb/pb.h"
3553
)
3654

37-
list (APPEND MINI_GMP_SRCS
38-
"vendor/mini-gmp/mini-gmp-helpers.c"
55+
list (APPEND MINI_GMP_SRCS
56+
"vendor/mini-gmp/mini-gmp-helpers.c"
3957
"vendor/mini-gmp/mini-gmp.c"
4058
)
41-
list (APPEND POSEIDON_SRCS
42-
"vendor/poseidon/sources/f251.c"
43-
"vendor/poseidon/sources/poseidon.c"
59+
list (APPEND POSEIDON_SRCS
60+
"vendor/poseidon/sources/f251.c"
61+
"vendor/poseidon/sources/poseidon.c"
4462
"vendor/poseidon/sources/poseidon_rc.c"
4563
)
4664

47-
OPTION(DEV_SWITCH "Additional features/logs to aid developers" OFF)
48-
OPTION(UNIT_TESTS_SWITCH "Compile build for main firmware or unit tests" OFF)
49-
OPTION(BTC_ONLY "Build firmware for Bitcoin only" OFF)
50-
51-
# Make static functions testable via unit-tests
52-
IF(UNIT_TESTS_SWITCH)
53-
add_compile_definitions( STATIC= )
54-
ELSE()
55-
add_compile_definitions( STATIC=static )
56-
ENDIF(UNIT_TESTS_SWITCH)
57-
5865
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
5966
add_compile_definitions(FIRMWARE_HASH_CALC=1)
6067
else()
@@ -68,13 +75,13 @@ else() # Simulator or default
6875
endif()
6976

7077
# Include nanopb source headers
71-
target_include_directories( ${EXECUTABLE} PRIVATE
72-
vendor/nanopb
73-
generated/proto
74-
vendor/mini-gmp
78+
target_include_directories( ${EXECUTABLE} PRIVATE
79+
vendor/nanopb
80+
generated/proto
81+
vendor/mini-gmp
7582
vendor/poseidon/sources
7683
)
7784

7885
# Enable support for dynamically allocated fields in nanopb
7986
# Ref: vendor/nanopb/pb.h
80-
add_compile_definitions(PB_ENABLE_MALLOC=1 PB_NO_ERRMSG=1)
87+
add_compile_definitions(PB_ENABLE_MALLOC=1 PB_NO_ERRMSG=1)

0 commit comments

Comments
 (0)