Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading