refactor(session): Auto generate session header using `course.header_… #48
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: Gem Release | ||
| on: | ||
| release: | ||
| types: [published] | ||
| workflow_dispatch: | ||
| inputs: | ||
| test_version: | ||
| description: 'Test version (e.g. 0.0.99-test) - skips gem pushes if provided' | ||
| required: false | ||
| type: string | ||
| default: '' | ||
| jobs: | ||
| build: | ||
| name: Build + Publish | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write # for commit, push, branch ops | ||
| pull-requests: write # for creating/editing PR + adding labels | ||
| packages: write | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
| - uses: ruby/setup-ruby@v1 | ||
| with: | ||
| bundler-cache: true | ||
| - name: Extract Versions and Package Name | ||
| run: | | ||
| OLD_VERSION=$(grep 'spec.version' *.gemspec | cut -d'"' -f2 | tr -d ' ') | ||
| PACKAGE_NAME=$(grep 'spec.name' *.gemspec | cut -d'"' -f2 | tr -d ' ') | ||
| if [ -n "${{ inputs.test_version }}" ]; then | ||
| NEW_VERSION="${{ inputs.test_version }}" | ||
| IS_TEST_MODE="true" | ||
| echo "TEST MODE: Using provided test version ${{ inputs.test_version }} (gem pushes will be skipped)" | ||
| else | ||
| NEW_VERSION=${GITHUB_REF_NAME#v} | ||
| IS_TEST_MODE="false" | ||
| echo "REAL MODE: Using tag-derived version $NEW_VERSION" | ||
| fi | ||
| echo "OLD_VERSION=$OLD_VERSION" >> $GITHUB_ENV | ||
| echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV | ||
| echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV | ||
| echo "IS_TEST_MODE=$IS_TEST_MODE" >> $GITHUB_ENV | ||
| RELEASE_BRANCH="release/v${NEW_VERSION}" | ||
| echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> $GITHUB_ENV | ||
| echo "Old version: $OLD_VERSION" | ||
| echo "New version: $NEW_VERSION" | ||
| echo "Package: $PACKAGE_NAME" | ||
| echo "Branch: $RELEASE_BRANCH" | ||
| echo "Test mode: $IS_TEST_MODE" | ||
| - name: Update Version in gemspec | ||
| run: | | ||
| sed -i -e "s/spec.version\s*=.*/spec.version = \"${{ env.VERSION }}\"/" \ | ||
| ${{ env.PACKAGE_NAME }}.gemspec | ||
| - name: Build Gem | ||
| run: gem build ${{ env.PACKAGE_NAME }}.gemspec | ||
| - name: Credentials & Push to RubyGems | ||
| if: env.IS_TEST_MODE != 'true' | ||
| run: | | ||
| mkdir -p $HOME/.gem | ||
| touch $HOME/.gem/credentials | ||
| chmod 0600 $HOME/.gem/credentials | ||
| printf -- "---\n:rubygems: ${{ secrets.RUBYGEMS_TOKEN }}\n" > $HOME/.gem/credentials | ||
| printf -- ":github: Bearer ${{ secrets.GEM_PUSH_TOKEN }}\n" >> $HOME/.gem/credentials | ||
| # Push to GitHub Packages | ||
| gem push \ | ||
| --key=github \ | ||
| --host=https://rubygems.pkg.github.com/${{ github.repository_owner }} \ | ||
| ${{ env.PACKAGE_NAME }}-*.gem | ||
| # Push to rubygems.org | ||
| gem push --key=rubygems ${{ env.PACKAGE_NAME }}-*.gem | ||
| - name: Commit version bump | ||
| run: | | ||
| git config user.name "GitHub Actions" | ||
| git config user.email "actions@github.com" | ||
| git add ${{ env.PACKAGE_NAME }}.gemspec | ||
| git commit -m "chore: bump version to ${{ env.VERSION }}" || echo "No changes to commit" | ||
| - name: Push to release branch | ||
| run: git push origin HEAD:refs/heads/${{ env.RELEASE_BRANCH }} --force | ||
| - name: Create PR and merge immediately | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| PR_TITLE="chore: update ${{ env.PACKAGE_NAME }} to ${{ env.VERSION }}" | ||
| PR_BODY="Automated version bump to ${{ env.VERSION }} after release publication.\n\nOld version was ${{ env.OLD_VERSION }}.\n\nMerging immediately via workflow." | ||
| # Ensure label exists (optional, for visibility only now) | ||
| gh label create "gem-release" --color "0E8A16" --description "Gem version bump PR" --force || true | ||
| # Check for existing open PR on this branch | ||
| EXISTING_PR=$(gh pr list --head "${{ env.RELEASE_BRANCH }}" --state open --json number --jq '.[0].number // ""') | ||
| if [ -n "$EXISTING_PR" ]; then | ||
| echo "Updating existing PR #$EXISTING_PR" | ||
| gh pr edit "$EXISTING_PR" \ | ||
| --title "$PR_TITLE" \ | ||
| --body "$PR_BODY" | ||
| gh pr reopen "$EXISTING_PR" || true | ||
| PR_NUMBER="$EXISTING_PR" | ||
| else | ||
| echo "Creating new PR" | ||
| PR_URL=$(gh pr create \ | ||
| --base main \ | ||
| --head "${{ env.RELEASE_BRANCH }}" \ | ||
| --title "$PR_TITLE" \ | ||
| --body "$PR_BODY" \ | ||
| --label "gem-release") | ||
| PR_NUMBER=$(echo "$PR_URL" | grep -o '[0-9]\+') | ||
| fi | ||
| # Immediately merge (squash is clean for version bumps; change to --merge or --rebase if preferred) | ||
| echo "Merging PR #$PR_NUMBER immediately" | ||
| gh pr merge "$PR_NUMBER" --squash --delete-branch || { | ||
| echo "Immediate merge failed (likely due to checks/protection). Falling back to enable auto-merge." | ||
| gh pr merge "$PR_NUMBER" --auto --squash --delete-branch || echo "Auto-merge enable also failed." | ||
| } | ||
| - name: Trim old package versions | ||
| if: env.IS_TEST_MODE != 'true' | ||
| uses: actions/delete-package-versions@v5 | ||
| with: | ||
| package-name: ${{ env.PACKAGE_NAME }} | ||
| package-type: rubygems | ||
| min-versions-to-keep: 5 | ||
| token: ${{ secrests.GEM_PUSH_TOKEN }} | ||