From 8447c479dd90a0b412a49acd08698ba5578951f1 Mon Sep 17 00:00:00 2001 From: Maciej Kobus Date: Sun, 11 Aug 2024 15:22:40 +0200 Subject: [PATCH] Create release workflow (#119) --- .github/workflows/00-release.yml | 120 +++++++++++++++++++++++++++++++ .github/workflows/10-build.yml | 2 + 2 files changed, 122 insertions(+) create mode 100644 .github/workflows/00-release.yml diff --git a/.github/workflows/00-release.yml b/.github/workflows/00-release.yml new file mode 100644 index 0000000..45e3550 --- /dev/null +++ b/.github/workflows/00-release.yml @@ -0,0 +1,120 @@ +name: Tag and Release + +on: + workflow_dispatch: + inputs: + version: + description: 'Version to tag' + required: true + default: 'v0.4' + type: string + is_draft: + description: 'Is draft release?' + default: false + type: boolean + is_prerelease: + description: 'Is prerelease?' + default: false + type: boolean + name: + description: 'Name' + required: false + default: '' + type: string + release_description: + description: 'Release description (Markdown supported)' + required: false + default: '' + type: string + +jobs: + tag: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Git + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + - name: Tag the branch + working-directory: ${{ github.workspace }} + run: | + git tag ${{ github.event.inputs.version }} + git push origin ${{ github.event.inputs.version }} + + build: + needs: tag + uses: ./.github/workflows/10-build.yml + + release: + runs-on: ubuntu-latest + needs: build + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-tags: true + + - name: Get commit hash + id: vars + run: | + git tag + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Determine Release Name + id: determine_name + run: | + if [ -z "${{ github.event.inputs.name }}" ]; then + echo "name=PicoBoot ${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT + else + echo "name=${{ github.event.inputs.name }}" >> $GITHUB_OUTPUT + fi + + - name: Retrieve artifact + uses: actions/download-artifact@v4 + with: + name: picoboot-${{ steps.vars.outputs.sha_short }} + path: dist/ + + - name: Prepare release description + run: | + touch release-description.md + echo "${{ github.event.inputs.release_description }}" >> release-description.md + + - name: Calculate artifact checksum + run: | + echo '```' >> release-description.md + cd dist/ + sha256sum picoboot_full.uf2 >> ../release-description.md + cd ../ + echo '```' >> release-description.md + + - name: Set up Git + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.event.inputs.version }} + release_name: ${{ steps.determine_name.outputs.name }} + body_path: ${{ github.workspace }}/release-description.md + draft: ${{ github.event.inputs.is_draft }} + prerelease: ${{ github.event.inputs.is_prerelease }} + + - name: Upload Release Asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ${{ github.workspace }}/dist/picoboot_full.uf2 + asset_name: picoboot_full.uf2 + asset_content_type: application/octet-stream diff --git a/.github/workflows/10-build.yml b/.github/workflows/10-build.yml index 779da13..f4d8f0d 100644 --- a/.github/workflows/10-build.yml +++ b/.github/workflows/10-build.yml @@ -7,6 +7,8 @@ on: branches: - main + workflow_call: + env: # Customize the CMake build BUILD_TYPE: RelWithDebInfo # Release, Debug, RelWithDebInfo