diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..969b1e5 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,76 @@ +name: Release + +on: + push: + tags: + # Tags in this repo are semver without a leading v (e.g. 0.19.0). + - "[0-9]+.[0-9]+.*" + workflow_dispatch: + inputs: + tag: + description: "Existing tag to publish a release asset for (e.g. 0.19.0)" + required: true + type: string + +permissions: {} + +jobs: + release: + name: Release + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Resolve version + id: version + env: + DISPATCH_TAG: ${{ inputs.tag }} + run: | + set -euo pipefail + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + VERSION="$DISPATCH_TAG" + else + VERSION="${GITHUB_REF_NAME}" + fi + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+ ]]; then + echo "::error::Unexpected tag '$VERSION'" >&2 + exit 1 + fi + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + - name: Checkout tag + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v4.2.2 + with: + ref: ${{ steps.version.outputs.version }} + persist-credentials: false + + - name: Create release archive + env: + VERSION: ${{ steps.version.outputs.version }} + run: | + set -euo pipefail + git archive --format=zip \ + --prefix="bash-env-nushell-${VERSION}/" \ + -o "bash-env-nushell-${VERSION}.zip" \ + HEAD + + - name: Create release and upload asset + env: + VERSION: ${{ steps.version.outputs.version }} + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + if gh release view "$VERSION" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then + gh release upload "$VERSION" \ + "bash-env-nushell-${VERSION}.zip" \ + --repo "$GITHUB_REPOSITORY" \ + --clobber + else + gh release create "$VERSION" \ + "bash-env-nushell-${VERSION}.zip" \ + --repo "$GITHUB_REPOSITORY" \ + --title "$VERSION" \ + --generate-notes + fi