Release #35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
upload_artifacts: 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 app_update.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 }}_app_update.bin" \ | |
--data-binary "@app_update.bin" | |
echo 'Uploaded build artifact ${{ env.BRANCH }}_app_update.bin as asset to release' >> $GITHUB_STEP_SUMMARY | |
- name: Upload app_update_sha256.sum | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
OWNER: ${{ github.repository_owner }} | |
REPO: ${{ github.event.repository.name }} | |
run: | | |
sha256sum app_update.bin > app_update_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 }}_app_update_sha256.sum" \ | |
--data-binary "@app_update_sha256.sum" | |
echo 'Uploaded build artifact ${{ env.BRANCH }}_app_update_sha256.sum as asset to release' >> $GITHUB_STEP_SUMMARY |