Skip to content

Commit fca9a05

Browse files
committed
chore(test): New build & push that uses built in gh for PR creation
1 parent 55bb569 commit fca9a05

File tree

1 file changed

+92
-29
lines changed

1 file changed

+92
-29
lines changed

.github/workflows/gem-push.yml

Lines changed: 92 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,126 @@ on:
55
types: [published]
66

77
workflow_dispatch:
8+
inputs:
9+
test_version:
10+
description: 'Test version (e.g. 0.0.99-test) - skips gem pushes if provided'
11+
required: false
12+
type: string
13+
default: ''
814

915
jobs:
1016
build:
1117
name: Build + Publish
1218
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write # for commit, push, branch ops
21+
pull-requests: write # for creating/editing PR + adding labels
22+
1323
steps:
1424
- uses: actions/checkout@v6
25+
with:
26+
fetch-depth: 0
27+
1528
- uses: ruby/setup-ruby@v1
1629
with:
17-
bundler-cache: true
30+
bundler-cache: true
1831

19-
- name: Get Current Version
20-
id: version
32+
- name: Extract Versions and Package Name
2133
run: |
22-
echo "OLD=$(grep spec.version *.gemspec | cut -d\" -f2)" >> $GITHUB_OUTPUT
23-
echo "NEW=$(echo ${GITHUB_REF_NAME:1})" >> $GITHUB_OUTPUT
34+
OLD_VERSION=$(grep 'spec.version' *.gemspec | cut -d'"' -f2 | tr -d ' ')
35+
PACKAGE_NAME=$(grep 'spec.name' *.gemspec | cut -d'"' -f2 | tr -d ' ')
2436
25-
- name: Get Package Name
26-
id: name
27-
run: echo "NAME=$(grep spec.name *.gemspec | cut -d\" -f2)" >> $GITHUB_OUTPUT
37+
if [ -n "${{ inputs.test_version }}" ]; then
38+
NEW_VERSION="${{ inputs.test_version }}"
39+
IS_TEST_MODE="true"
40+
echo "TEST MODE: Using provided test version ${{ inputs.test_version }} (gem pushes will be skipped)"
41+
else
42+
NEW_VERSION=${GITHUB_REF_NAME#v}
43+
IS_TEST_MODE="false"
44+
echo "REAL MODE: Using tag-derived version $NEW_VERSION"
45+
fi
2846
29-
- name: Update Version
30-
run: |
31-
sed -i -e '/spec.version/c\ spec.version = "${{ steps.version.outputs.NEW }}"' \
32-
${{ steps.name.outputs.NAME }}.gemspec
47+
echo "OLD_VERSION=$OLD_VERSION" >> $GITHUB_ENV
48+
echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV
49+
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
50+
echo "IS_TEST_MODE=$IS_TEST_MODE" >> $GITHUB_ENV
3351
34-
- name: Remove non-theme related assets
35-
run: rm -rf assets/audio
52+
RELEASE_BRANCH="release/v${NEW_VERSION}"
53+
echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> $GITHUB_ENV
3654
37-
- name: Build
38-
run: gem build ${{ steps.name.outputs.NAME }}.gemspec
55+
echo "Old version: $OLD_VERSION"
56+
echo "New version: $VERSION"
57+
echo "Package: $PACKAGE_NAME"
58+
echo "Branch: $RELEASE_BRANCH"
59+
echo "Test mode: $IS_TEST_MODE"
3960
40-
- name: Credentials & Push
61+
- name: Update Version in gemspec
62+
run: |
63+
sed -i -e "s/spec.version\s*=.*/spec.version = \"${{ env.VERSION }}\"/" \
64+
${{ env.PACKAGE_NAME }}.gemspec
65+
66+
- name: Build Gem
67+
run: gem build ${{ env.PACKAGE_NAME }}.gemspec
68+
69+
- name: Credentials & Push to RubyGems
70+
if: env.IS_TEST_MODE != 'true'
4171
run: |
4272
mkdir -p $HOME/.gem
4373
touch $HOME/.gem/credentials
4474
chmod 0600 $HOME/.gem/credentials
4575
printf -- "---\n:rubygems: ${{ secrets.RUBYGEMS_TOKEN }}\n" > $HOME/.gem/credentials
4676
printf -- ":github: Bearer ${{ secrets.GITHUB_TOKEN }}\n" >> $HOME/.gem/credentials
77+
78+
# Push to GitHub Packages
4779
gem push \
4880
--key=github \
4981
--host=https://rubygems.pkg.github.com/${{ github.repository_owner }} \
50-
${{ steps.name.outputs.NAME }}-*.gem
51-
gem push --key=rubygems ${{ steps.name.outputs.NAME }}-*.gem
82+
${{ env.PACKAGE_NAME }}-*.gem
5283
53-
- name: Version PR
54-
uses: peter-evans/create-pull-request@v8
55-
with:
56-
commit-message: Update to ${{ steps.version.outputs.NEW }}
57-
title: Update ${{ steps.name.outputs.NAME }} (${{ steps.version.outputs.NEW }})
58-
body: ${{ steps.old_version.outputs.OLD }}
59-
branch: update-version
60-
base: main
84+
# Push to rubygems.org
85+
gem push --key=rubygems ${{ env.PACKAGE_NAME }}-*.gem
86+
87+
- name: Commit version bump
88+
run: |
89+
git config user.name "GitHub Actions"
90+
git config user.email "actions@github.com"
91+
92+
git add ${{ env.PACKAGE_NAME }}.gemspec
93+
git commit -m "chore: bump version to ${{ env.VERSION }}" || echo "No changes to commit"
94+
95+
- name: Push to release branch
96+
run: git push origin HEAD:${{ env.RELEASE_BRANCH }} --force
97+
98+
- name: Create or update PR with auto-merge label
99+
env:
100+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
run: |
102+
PR_TITLE="chore: update ${{ env.PACKAGE_NAME }} to ${{ env.VERSION }}"
103+
PR_BODY="Automated version bump to ${{ env.VERSION }} after release publication.\n\nOld version was ${{ env.OLD_VERSION }}."
104+
105+
# Check for existing open PR on this branch
106+
EXISTING_PR=$(gh pr list --head "${{ env.RELEASE_BRANCH }}" --state open --json number --jq '.[0].number // ""')
107+
108+
if [ -n "$EXISTING_PR" ]; then
109+
echo "Updating existing PR #$EXISTING_PR"
110+
gh pr edit "$EXISTING_PR" \
111+
--title "$PR_TITLE" \
112+
--body "$PR_BODY"
113+
gh pr reopen "$EXISTING_PR" || true
114+
else
115+
echo "Creating new PR"
116+
gh pr create \
117+
--base main \
118+
--head "${{ env.RELEASE_BRANCH }}" \
119+
--title "$PR_TITLE" \
120+
--body "$PR_BODY" \
121+
--label "auto-merge"
122+
fi
61123
62-
- name: Trim old packages
124+
- name: Trim old package versions
125+
if: env.IS_TEST_MODE != 'true'
63126
uses: actions/delete-package-versions@v5
64127
with:
65-
package-name: ${{ steps.name.outputs.NAME }}
128+
package-name: ${{ env.PACKAGE_NAME }}
66129
package-type: rubygems
67130
min-versions-to-keep: 5

0 commit comments

Comments
 (0)