diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a4f3585..50be919 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,16 +1,59 @@ -name: Build Specview Executables +name: Build and Release Specview on: push: tags: - 'v*' # Trigger on version tags like v1.0.0 + workflow_dispatch: + inputs: + version: + description: 'Version tag for the release (e.g. v0.2.0-test). A pre-release will be created with this name.' + required: true + default: 'v0.0.0-test' + +permissions: + contents: write # needed to create GitHub releases jobs: - build: + setup: + runs-on: ubuntu-22.04 + outputs: + release_tag: ${{ steps.get-tag.outputs.release_tag }} + prerelease: ${{ steps.get-tag.outputs.prerelease }} + steps: + - name: Determine release tag + id: get-tag + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "release_tag=${{ inputs.version }}" >> $GITHUB_OUTPUT + echo "prerelease=true" >> $GITHUB_OUTPUT + else + echo "release_tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT + echo "prerelease=false" >> $GITHUB_OUTPUT + fi + + build-binary: + needs: [setup] runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-22.04, macos-latest, windows-latest] #, windows-11-arm] + include: + - os: ubuntu-22.04 + platform: linux + binary_src: dist/specview + binary_dst_suffix: linux + binary_ext: "" + - os: macos-latest + platform: macos + binary_src: dist/specview + binary_dst_suffix: macos + binary_ext: "" + - os: windows-latest + platform: windows + binary_src: dist/specview.exe + binary_dst_suffix: windows + binary_ext: ".exe" + steps: - name: Checkout code uses: actions/checkout@v4 @@ -19,7 +62,7 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.12' - + - name: Install uv (Unix) if: runner.os != 'Windows' run: | @@ -36,9 +79,75 @@ jobs: uv sync --group build --group dev uv run poe build-pyinstaller - - name: Upload executable artifact + - name: Rename binary with version and platform + shell: bash + run: | + VERSION="${{ needs.setup.outputs.release_tag }}" + VERSION="${VERSION#v}" # strip leading 'v' + BINARY_NAME="specview-${VERSION}-${{ matrix.binary_dst_suffix }}${{ matrix.binary_ext }}" + mv "${{ matrix.binary_src }}" "dist/${BINARY_NAME}" + echo "BINARY_NAME=${BINARY_NAME}" >> $GITHUB_ENV + + - name: Upload binary artifact + uses: actions/upload-artifact@v4 + with: + name: specview-${{ matrix.platform }} + path: dist/${{ env.BINARY_NAME }} + + build-wheel: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install uv + run: | + curl -LsSf https://astral.sh/uv/install.sh | sh + + - name: Build wheel + run: | + uv build + + - name: Upload wheel artifact uses: actions/upload-artifact@v4 with: - name: specview-${{ runner.os }} - path: | - dist/* + name: specview-wheel + path: dist/*.whl + + release: + needs: [setup, build-binary, build-wheel] + runs-on: ubuntu-22.04 + + steps: + - name: Download all artifacts + uses: actions/download-artifact@v4.1.3 + with: + path: release-assets + # merge-multiple flattens all artifacts into one directory; filenames are + # unique by design (platform suffix on binaries, package name on the wheel). + merge-multiple: true + + - name: Create GitHub Release + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: | + RELEASE_TAG="${{ needs.setup.outputs.release_tag }}" + PRERELEASE_FLAG="" + if [ "${{ needs.setup.outputs.prerelease }}" = "true" ]; then + PRERELEASE_FLAG="--prerelease" + fi + # Create the release; if it already exists (e.g. workflow re-run), upload + # the files to the existing release instead. + gh release create "${RELEASE_TAG}" \ + --title "Release ${RELEASE_TAG}" \ + --generate-notes \ + ${PRERELEASE_FLAG} \ + release-assets/* \ + || gh release upload "${RELEASE_TAG}" release-assets/* --clobber diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 832afdb..ba5bd79 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/checkout@v4 - name: Set up Python 3.12 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.12"