Skip to content
Closed
Show file tree
Hide file tree
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
92 changes: 92 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---

name: Release

on:
push:
tags:
- v*
- test-*

jobs:
test:
name: Run tests
uses: ./.github/workflows/test.yml

verify-version:
name: Verify Gem version matches tag
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
-
name: Check version
run: |
TAG=${GITHUB_REF#refs/tags/}

# Skip version check for test tags
if [[ "$TAG" == test-* ]]; then
echo "Test tag detected, skipping version check"
exit 0
fi

TAG_VERSION=${TAG#v}
GEM_VERSION=$(grep -E "VERSION = \"[0-9]+\.[0-9]+\.[0-9]+\"" \
lib/semian/version.rb | grep -oE "[0-9]+\.[0-9]+\.[0-9]+")
echo "Tag version: $TAG_VERSION"
echo "Gem version: $GEM_VERSION"
if [ "$TAG_VERSION" != "$GEM_VERSION" ]; then
echo "Error: Tag version ($TAG_VERSION) does not match gem version ($GEM_VERSION)"
exit 1
fi
echo "Version check passed!"

build-and-release:
name: Build gem and create GitHub release
runs-on: ubuntu-latest
needs: [test, verify-version]
permissions:
contents: write
steps:
-
name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
-
name: Set up Ruby
uses: ruby/[email protected]
with:
ruby-version: "3.4"
bundler-cache: true
-
name: Build C extension
run: bundle exec rake build
-
name: Build gem
run: |
gem build semian.gemspec
-
name: Generate SHA512 checksum
run: |
for gem in semian-*.gem; do
sha512sum "$gem" > "${gem}.sha512"
done
-
name: Extract version from tag
id: tag
run: |
tag=${GITHUB_REF#refs/tags/}
echo "tag=$tag" >> $GITHUB_OUTPUT
-
name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: |
tag="${{ steps.tag.outputs.tag }}"
gh release create "$tag" \
--title "$tag" \
--generate-notes \
semian-*.gem \
semian-*.gem.sha512

1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_call:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is that? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows for the workflow to be called from other workflows (release workflow)


concurrency:
group: ${{ github.ref }}-test
Expand Down