Skip to content

Commit

Permalink
Add release workflow and upload artifacts step to GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil committed Nov 5, 2024
1 parent f1576c1 commit 605966b
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 1 deletion.
9 changes: 8 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_call:

jobs:
check-format:
Expand Down Expand Up @@ -36,4 +37,10 @@ jobs:
run: cmake --build build --config ${{ matrix.build_type }}

- name: Install
run: cmake --install build --prefix ${{ github.workspace }}/dist --config ${{ matrix.build_type }}
run: cmake --install build --prefix ${{ github.workspace }}/dist --config ${{ matrix.build_type }}

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.build_type }}
path: ${{ github.workspace }}/dist
126 changes: 126 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Release
run-name: ${{ github.ref_name }} release run 🚀
on:
push:
branches:
- main
tags:
- '*'
permissions:
contents: write
concurrency:
group: '${{ github.workflow }} @ ${{ github.ref }}'
cancel-in-progress: ${{ github.ref_type == 'tag' }}
jobs:
build-project:
name: Build Project 🧱
uses: ./.github/workflows/build.yaml
secrets: inherit
permissions:
contents: read

create-release:
name: Create Release 🛫
if: github.ref_type == 'tag'
runs-on: ubuntu-22.04
needs: build-project
defaults:
run:
shell: bash
steps:
- name: Check Release Tag ☑️
id: check
run: |
: Check Release Tag ☑️
if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi
shopt -s extglob
case "${GITHUB_REF_NAME}" in
+([0-9]).+([0-9]).+([0-9]) )
echo 'validTag=true' >> $GITHUB_OUTPUT
echo 'prerelease=false' >> $GITHUB_OUTPUT
echo "version=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
;;
+([0-9]).+([0-9]).+([0-9])-@(beta|rc)*([0-9]) )
echo 'validTag=true' >> $GITHUB_OUTPUT
echo 'prerelease=true' >> $GITHUB_OUTPUT
echo "version=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
;;
*) echo 'validTag=false' >> $GITHUB_OUTPUT ;;
esac
- name: Download Build Artifacts 📥
uses: actions/download-artifact@v4
if: fromJSON(steps.check.outputs.validTag)
id: download

- name: Print downloaded artifacts 📥
if: fromJSON(steps.check.outputs.validTag)
run: |
: Print downloaded artifacts 📥
if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi
shopt -s extglob
ls -laR ${{ steps.download.outputs.artifacts }}
- name: Rename Files 🏷️
if: fromJSON(steps.check.outputs.validTag)
run: |
: Rename Files 🏷️
if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi
shopt -s extglob
shopt -s nullglob
commit_hash="${GITHUB_SHA:0:9}"
variants=(
'linux'
'macos'
'windows'
)
mkdir -p "${{ github.workspace }}/uploads"
for variant in "${variants[@]}"; do
candidates=(*-${variant}/@(*))
for candidate in "${candidates[@]}"; do
cp "${candidate}" "${{ github.workspace }}/uploads/moonshine-cpp-${variant}-${GITHUB_REF_NAME}.${candidate##*.}"
done
done
- name: Upload Release Artifacts 📤
if: fromJSON(steps.check.outputs.validTag)
uses: actions/upload-artifact@v4
with:
name: moonshine-cpp-${GITHUB_REF_NAME}
path: uploads

- name: Generate Checksums 🪪
if: fromJSON(steps.check.outputs.validTag)
run: |
: Generate Checksums 🪪
if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi
shopt -s extglob
echo "### Checksums" > ${{ github.workspace }}/CHECKSUMS.txt
# find the files from the above step and generate checksums
for file in ${{ github.workspace }}/uploads/moonshine-cpp-*; do
echo " ${file##*/}: $(sha256sum "${file}" | cut -d " " -f 1)" >> ${{ github.workspace }}/CHECKSUMS.txt
done
- name: Create Release 🛫
if: fromJSON(steps.check.outputs.validTag)
id: create_release
uses: softprops/action-gh-release@v2
with:
draft: false
name: Moonshine.cpp v${{ steps.check.outputs.version }}
generate_release_notes: true
body_path: ${{ github.workspace }}/CHECKSUMS.txt
files: |
${{ github.workspace }}/uploads/note-taker-*.zip
${{ github.workspace }}/uploads/note-taker-*.exe
${{ github.workspace }}/uploads/note-taker-*.dmg
${{ github.workspace }}/uploads/note-taker-*.tar

0 comments on commit 605966b

Please sign in to comment.