|
| 1 | +name: Create Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + create-release: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + steps: |
| 10 | + - name: Checkout code |
| 11 | + uses: actions/checkout@v4 |
| 12 | + |
| 13 | + - name: Extract version from Cargo.toml |
| 14 | + id: extract_version |
| 15 | + run: | |
| 16 | + VERSION=$(grep "^version" src/rust/fcb_core/Cargo.toml | head -1 | cut -d'"' -f2) |
| 17 | + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 18 | + echo "Extracted version: $VERSION" |
| 19 | +
|
| 20 | + - name: Check if tag exists |
| 21 | + id: check_tag |
| 22 | + run: | |
| 23 | + if git ls-remote --tags origin | grep -q "refs/tags/v${{ steps.extract_version.outputs.VERSION }}"; then |
| 24 | + echo "TAG_EXISTS=true" >> $GITHUB_OUTPUT |
| 25 | + else |
| 26 | + echo "TAG_EXISTS=false" >> $GITHUB_OUTPUT |
| 27 | + fi |
| 28 | +
|
| 29 | + - name: Generate release notes |
| 30 | + if: steps.check_tag.outputs.TAG_EXISTS == 'false' |
| 31 | + id: release_notes |
| 32 | + run: | |
| 33 | + # Get the latest tag |
| 34 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 35 | +
|
| 36 | + # Generate changelog |
| 37 | + echo "RELEASE_NOTES<<EOF" >> $GITHUB_OUTPUT |
| 38 | + echo "## What's Changed" >> $GITHUB_OUTPUT |
| 39 | + echo "" >> $GITHUB_OUTPUT |
| 40 | +
|
| 41 | + if [ -z "$LATEST_TAG" ]; then |
| 42 | + echo "Initial release" >> $GITHUB_OUTPUT |
| 43 | + else |
| 44 | + # Get commit messages since last tag |
| 45 | + git log $LATEST_TAG..HEAD --pretty=format:"- %s" >> $GITHUB_OUTPUT |
| 46 | + fi |
| 47 | +
|
| 48 | + echo "" >> $GITHUB_OUTPUT |
| 49 | + echo "" >> $GITHUB_OUTPUT |
| 50 | + echo "### Crate Version: ${{ steps.extract_version.outputs.VERSION }}" >> $GITHUB_OUTPUT |
| 51 | + echo "" >> $GITHUB_OUTPUT |
| 52 | +
|
| 53 | + # Check npm version |
| 54 | + NPM_VERSION=$(grep "\"version\"" src/ts/package.json | cut -d'"' -f4) |
| 55 | + echo "### NPM Version: $NPM_VERSION" >> $GITHUB_OUTPUT |
| 56 | + echo "" >> $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${LATEST_TAG}...v${{ steps.extract_version.outputs.VERSION }}" >> $GITHUB_OUTPUT |
| 59 | + echo "EOF" >> $GITHUB_OUTPUT |
| 60 | +
|
| 61 | + - name: Create and push tag |
| 62 | + if: steps.check_tag.outputs.TAG_EXISTS == 'false' |
| 63 | + run: | |
| 64 | + git config --global user.name "github-actions[bot]" |
| 65 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 66 | + git tag -a "v${{ steps.extract_version.outputs.VERSION }}" -m "Release v${{ steps.extract_version.outputs.VERSION }}" |
| 67 | + git push origin "v${{ steps.extract_version.outputs.VERSION }}" |
| 68 | +
|
| 69 | + - name: Create GitHub Release |
| 70 | + if: steps.check_tag.outputs.TAG_EXISTS == 'false' |
| 71 | + uses: actions/create-release@v1 |
| 72 | + env: |
| 73 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 74 | + with: |
| 75 | + tag_name: v${{ steps.extract_version.outputs.VERSION }} |
| 76 | + release_name: v${{ steps.extract_version.outputs.VERSION }} |
| 77 | + body: ${{ steps.release_notes.outputs.RELEASE_NOTES }} |
| 78 | + draft: false |
| 79 | + prerelease: false |
0 commit comments