fix: visual selection on send #29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| if: startsWith(github.event.head_commit.message || '', 'RELEASE:') || startsWith(github.event.head_commit.message || '', 'release:') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract tag from commit message | |
| id: extract_tag | |
| run: | | |
| COMMIT_MSG="${{ github.event.head_commit.message }}" | |
| FIRST_LINE="$(echo "$COMMIT_MSG" | head -n 1)" | |
| TAG="$(echo "$FIRST_LINE" | sed -E 's/^[Rr][Ee][Ll][Ee][Aa][Ss][Ee]: *//')" | |
| if [ -z "$TAG" ]; then | |
| echo "Error: no tag found in commit message" | |
| exit 1 | |
| fi | |
| if ! [[ "$TAG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then | |
| echo "Error: tag must be in format v0.0.0, v0.0.0-alpha, or v0.0.0-rc.1" | |
| exit 1 | |
| fi | |
| if [[ ! "$TAG" =~ ^v ]]; then | |
| TAG="v$TAG" | |
| fi | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| echo "Creating release for tag: $TAG" | |
| - name: Check if tag exists | |
| id: check_tag | |
| run: | | |
| TAG="${{ steps.extract_tag.outputs.tag }}" | |
| if git ls-remote --tags origin "refs/tags/${TAG}" | grep -q .; then | |
| echo "Tag ${TAG} already exists, skipping tag creation" | |
| echo "tag_exists=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "tag_exists=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Create and push tag | |
| if: steps.check_tag.outputs.tag_exists != 'true' | |
| run: | | |
| TAG="${{ steps.extract_tag.outputs.tag }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag "$TAG" | |
| git push origin "$TAG" | |
| - name: Get previous tag | |
| id: get_previous_tag | |
| run: | | |
| TAG="${{ steps.extract_tag.outputs.tag }}" | |
| PREVIOUS_TAG="$(git describe --tags --abbrev=0 "${TAG}^" 2>/dev/null || true)" | |
| echo "previous_tag=$PREVIOUS_TAG" >> "$GITHUB_OUTPUT" | |
| echo "Previous tag: $PREVIOUS_TAG" | |
| - name: Generate release notes | |
| run: | | |
| TAG="${{ steps.extract_tag.outputs.tag }}" | |
| PREVIOUS_TAG="${{ steps.get_previous_tag.outputs.previous_tag }}" | |
| if [ -n "$PREVIOUS_TAG" ]; then | |
| COMMITS="$(git log --pretty=format:'- %s (%h)' "${PREVIOUS_TAG}..${TAG}" 2>/dev/null || git log --pretty=format:'- %s (%h)' -20)" | |
| CHANGELOG_LINE="**Full Changelog**: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/compare/${PREVIOUS_TAG}...${TAG}" | |
| else | |
| COMMITS="$(git log --pretty=format:'- %s (%h)' -20)" | |
| CHANGELOG_LINE="**Full Changelog**: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" | |
| fi | |
| NOTES="## What's Changed | |
| ${COMMITS} | |
| ${CHANGELOG_LINE}" | |
| echo "$NOTES" > release_notes.md | |
| echo "Generated release notes" | |
| - name: Check if release exists | |
| id: check_release | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| run: | | |
| TAG="${{ steps.extract_tag.outputs.tag }}" | |
| STATUS="$(curl -s -o /dev/null -w '%{http_code}' \ | |
| -H "Authorization: Bearer ${GITHUB_TOKEN}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}")" | |
| if [ "$STATUS" = "200" ]; then | |
| echo "Release for ${TAG} already exists, skipping" | |
| echo "release_exists=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "release_exists=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Create GitHub release | |
| if: steps.check_release.outputs.release_exists != 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| run: | | |
| TAG="${{ steps.extract_tag.outputs.tag }}" | |
| NOTES="$(cat release_notes.md)" | |
| NOTES_ESCAPED="$(printf '%s' "$NOTES" | python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))')" | |
| if [[ "$TAG" == *-* ]]; then | |
| PRERELEASE=true | |
| else | |
| PRERELEASE=false | |
| fi | |
| curl --fail-with-body -X POST \ | |
| -H "Authorization: Bearer ${GITHUB_TOKEN}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Content-Type: application/json" \ | |
| "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases" \ | |
| -d "{ | |
| \"tag_name\": \"${TAG}\", | |
| \"name\": \"${TAG}\", | |
| \"body\": ${NOTES_ESCAPED}, | |
| \"draft\": false, | |
| \"prerelease\": ${PRERELEASE} | |
| }" |