Skip to content

Commit ef03edc

Browse files
committed
Merge pull-request #20
2 parents 5a64085 + 5d22e45 commit ef03edc

1 file changed

Lines changed: 209 additions & 0 deletions

File tree

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
name: Version Packages Create Release Branch and Publish
2+
3+
on:
4+
workflow_dispatch: # allows manual invocation
5+
push:
6+
tags:
7+
- "v*.*.*" # triggers on tags like v1.0.0
8+
9+
permissions:
10+
contents: write
11+
id-token: write # required for RubyGems trusted publishing (OIDC)
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
# https://github.com/actions/checkout
18+
- name: Checkout
19+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
with:
21+
fetch-depth: 0 # required for git tags and history
22+
ref: ${{ github.event.repository.default_branch }}
23+
24+
# https://github.com/ruby/setup-ruby
25+
- name: Set up Ruby
26+
uses: ruby/setup-ruby@80740b3b13bf9857e28854481ca95a84e78a2bdf # v1.284.0
27+
with:
28+
ruby-version: '3.3'
29+
bundler-cache: true
30+
working-directory: turnkey_client
31+
32+
# Check if there are pending changesets
33+
- name: Check for pending releases
34+
run: |
35+
echo "Checking for pending changesets..."
36+
git fetch origin main
37+
CHANGESET_COUNT=$(find .changesets -maxdepth 1 -name '*.md' ! -name '_*' 2>/dev/null | wc -l)
38+
if [ "$CHANGESET_COUNT" -eq 0 ]; then
39+
echo "No unreleased changesets found, exiting"
40+
exit 1
41+
fi
42+
echo "Found $CHANGESET_COUNT pending changeset(s), continuing"
43+
44+
- name: Run rubocop
45+
run: |
46+
gem install rubocop
47+
rubocop
48+
49+
- name: Validate gem builds
50+
working-directory: turnkey_client
51+
run: gem build turnkey_client.gemspec
52+
53+
version-and-rebuild:
54+
runs-on: ubuntu-latest
55+
needs: build
56+
steps:
57+
- name: Checkout
58+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
59+
with:
60+
fetch-depth: 0 # required for git tags and history
61+
ref: ${{ github.event.repository.default_branch }}
62+
63+
- name: Set up Ruby
64+
uses: ruby/setup-ruby@80740b3b13bf9857e28854481ca95a84e78a2bdf # v1.284.0
65+
with:
66+
ruby-version: '3.3'
67+
bundler-cache: true
68+
working-directory: turnkey_client
69+
70+
- name: Configure Git User
71+
run: |
72+
git config user.name "tkhq-deploy"
73+
git config user.email "github@turnkey.engineering"
74+
75+
- name: Create and switch to release branch
76+
run: |
77+
git fetch origin
78+
git checkout -B release/${{ github.ref_name }} origin/release/${{ github.ref_name }} || \
79+
git checkout -B release/${{ github.ref_name }}
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
83+
# Process changesets, bump version, and generate changelog
84+
- name: Version and prepare release
85+
run: |
86+
rm -f .changesets/_current_release.json
87+
make prepare-release
88+
89+
- name: Validate gem builds with updated version
90+
working-directory: turnkey_client
91+
run: |
92+
gem build turnkey_client.gemspec
93+
rm -f *.gem
94+
95+
- name: Debug Git Status
96+
run: |
97+
echo "Git status before commit:"
98+
git status --short
99+
echo "Listing .changesets directory:"
100+
ls -la .changesets || echo ".changesets directory not found"
101+
102+
- name: Commit versioned changes
103+
run: |
104+
git add -A
105+
git commit -m "chore: release turnkey_client" || echo "No changes to commit"
106+
env:
107+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108+
109+
- name: Push changes to release branch
110+
run: |
111+
git push -u origin release/${{ github.ref_name }}
112+
env:
113+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
115+
- name: Upload release artifacts
116+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
117+
with:
118+
name: release-artifacts-${{ github.ref_name }}
119+
path: |
120+
turnkey_client/**
121+
!turnkey_client/vendor
122+
!turnkey_client/*.gem
123+
turnkey_client_inputs/config.json
124+
.changesets/**
125+
CHANGELOG.md
126+
retention-days: 7
127+
128+
prepare-release:
129+
runs-on: ubuntu-latest
130+
needs: version-and-rebuild
131+
steps:
132+
# https://github.com/actions/checkout
133+
- name: Checkout
134+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
135+
with:
136+
fetch-depth: 0 # required for git tags and history
137+
ref: release/${{ github.ref_name }}
138+
139+
- name: Create GitHub Release
140+
uses: softprops/action-gh-release@da05d552573ad5aba039eaac05058a918a7bf631 # v2.2.2
141+
with:
142+
tag_name: ${{ github.ref_name }}
143+
name: Release ${{ github.ref_name }}
144+
generate_release_notes: true
145+
draft: true
146+
prerelease: false
147+
env:
148+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149+
150+
publish:
151+
needs: prepare-release
152+
runs-on:
153+
group: package-deploy
154+
environment: production # require manual approval for production deployments
155+
permissions:
156+
contents: write
157+
id-token: write # required for RubyGems trusted publishing (OIDC)
158+
159+
steps:
160+
- name: Checkout
161+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
162+
with:
163+
fetch-depth: 0 # required for git tags and history
164+
ref: release/${{ github.ref_name }}
165+
166+
- name: Configure Git User
167+
run: |
168+
git config user.name "tkhq-deploy"
169+
git config user.email "github@turnkey.engineering"
170+
171+
- name: Set up Ruby
172+
uses: ruby/setup-ruby@80740b3b13bf9857e28854481ca95a84e78a2bdf # v1.284.0
173+
with:
174+
ruby-version: '3.3'
175+
bundler-cache: true
176+
working-directory: turnkey_client
177+
178+
# Download the release artifacts generated by version-and-rebuild
179+
- name: Download release artifacts
180+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
181+
with:
182+
name: release-artifacts-${{ github.ref_name }}
183+
path: .
184+
185+
# OIDC trusted publishing
186+
# Uses the same credentials action as rubygems/release-gem
187+
- name: Configure trusted publishing credentials
188+
uses: rubygems/configure-rubygems-credentials@bc6dd217f8a4f919d6835fcfefd470ef821f5c44 # v1.0.0
189+
190+
- name: Build gem
191+
working-directory: turnkey_client
192+
run: |
193+
gem build turnkey_client.gemspec
194+
echo "Built gem:"
195+
ls -la *.gem
196+
197+
- name: Publish to RubyGems
198+
working-directory: turnkey_client
199+
run: |
200+
echo "Publishing to RubyGems..."
201+
gem push turnkey_client-*.gem || {
202+
echo "Publish failed. Check logs above.";
203+
exit 1;
204+
}
205+
echo "Successfully published to RubyGems"
206+
207+
- name: Wait for release to propagate
208+
working-directory: turnkey_client
209+
run: gem exec rubygems-await *.gem

0 commit comments

Comments
 (0)