Skip to content

Commit 21159f5

Browse files
authored
Merge pull request #1 from TwilightCoders/develop
🚀 Modernize thaw gem with comprehensive safety system and C extension
2 parents a2b9c45 + c98d72a commit 21159f5

19 files changed

Lines changed: 1105 additions & 86 deletions

.github/workflows/ci.yml

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, develop, release/**]
6+
pull_request:
7+
branches: [main, develop]
8+
9+
permissions:
10+
actions: write
11+
contents: read
12+
id-token: write
13+
packages: write
14+
15+
jobs:
16+
test:
17+
runs-on: ${{ matrix.os }}
18+
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ubuntu-latest, windows-latest, macos-latest]
23+
ruby-version: ["2.7", "3.0", "3.1", "3.2", "3.3"]
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Set up Ruby ${{ matrix.ruby-version }}
29+
uses: ruby/setup-ruby@v1
30+
with:
31+
ruby-version: ${{ matrix.ruby-version }}
32+
bundler-cache: true
33+
34+
- name: Install build dependencies
35+
if: runner.os == 'Linux'
36+
run: sudo apt-get update && sudo apt-get install -y build-essential
37+
38+
- name: Install dependencies and compile extension
39+
run: |
40+
bundle install
41+
# Compile C extension using rake (standard for C extension gems)
42+
bundle exec rake compile
43+
44+
- name: Run tests with coverage
45+
run: bundle exec rspec
46+
47+
- name: Upload coverage artifact (Ruby 3.3 on Ubuntu only)
48+
if: matrix.ruby-version == '3.3' && matrix.os == 'ubuntu-latest'
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: coverage-report
52+
path: coverage/
53+
retention-days: 1
54+
55+
- name: Run RuboCop (Ruby 3.3 on Ubuntu only)
56+
if: matrix.ruby-version == '3.3' && matrix.os == 'ubuntu-latest'
57+
run: bundle exec rubocop || true
58+
continue-on-error: true
59+
60+
coverage:
61+
runs-on: ubuntu-latest
62+
needs: test
63+
64+
steps:
65+
- uses: actions/checkout@v4
66+
67+
- name: Download coverage artifact
68+
uses: actions/download-artifact@v4
69+
with:
70+
name: coverage-report
71+
path: coverage/
72+
73+
- name: Upload coverage to Qlty
74+
uses: qltysh/qlty-action/coverage@v1
75+
continue-on-error: true
76+
env:
77+
QLTY_COVERAGE_TOKEN: ${{ secrets.QLTY_COVERAGE_TOKEN }}
78+
with:
79+
oidc: true
80+
files: coverage/coverage.json
81+
82+
- name: Run Qlty code quality checks
83+
run: |
84+
curl -sSfL https://qlty.sh | sh
85+
echo "$HOME/.qlty/bin" >> $GITHUB_PATH
86+
~/.qlty/bin/qlty check || true
87+
continue-on-error: true
88+
89+
security:
90+
runs-on: ubuntu-latest
91+
92+
steps:
93+
- uses: actions/checkout@v4
94+
95+
- name: Set up Ruby
96+
uses: ruby/setup-ruby@v1
97+
with:
98+
ruby-version: "3.3"
99+
bundler-cache: true
100+
101+
- name: Run bundle audit
102+
run: |
103+
gem install bundler-audit
104+
bundle audit --update || true
105+
continue-on-error: true
106+
107+
build:
108+
runs-on: ubuntu-latest
109+
needs: [test, coverage, security]
110+
if: github.event_name == 'push'
111+
112+
steps:
113+
- uses: actions/checkout@v4
114+
115+
- name: Set up Ruby
116+
uses: ruby/setup-ruby@v1
117+
with:
118+
ruby-version: "3.3"
119+
bundler-cache: true
120+
121+
- name: Modify version for develop branch
122+
if: github.ref == 'refs/heads/develop'
123+
run: |
124+
SHORT_SHA=$(git rev-parse --short HEAD)
125+
sed -i "s/VERSION = \"\([^\"]*\)\"/VERSION = \"\1.dev.${SHORT_SHA}\"/" lib/thaw/version.rb
126+
echo "VERSION_SUFFIX=.dev.${SHORT_SHA}" >> $GITHUB_ENV
127+
128+
- name: Modify version for release branch
129+
if: startsWith(github.ref, 'refs/heads/release/')
130+
run: |
131+
SHORT_SHA=$(git rev-parse --short HEAD)
132+
sed -i "s/VERSION = \"\([^\"]*\)\"/VERSION = \"\1.rc.${SHORT_SHA}\"/" lib/thaw/version.rb
133+
echo "VERSION_SUFFIX=.rc.${SHORT_SHA}" >> $GITHUB_ENV
134+
135+
- name: Set version suffix for main
136+
if: github.ref == 'refs/heads/main'
137+
run: echo "VERSION_SUFFIX=" >> $GITHUB_ENV
138+
139+
- name: Build gem
140+
run: gem build thaw.gemspec
141+
142+
- name: Get gem info
143+
id: gem_info
144+
run: |
145+
GEM_FILE=$(ls *.gem)
146+
GEM_VERSION=$(echo $GEM_FILE | sed 's/thaw-\(.*\)\.gem/\1/')
147+
echo "gem_file=$GEM_FILE" >> $GITHUB_OUTPUT
148+
echo "gem_version=$GEM_VERSION" >> $GITHUB_OUTPUT
149+
150+
- name: Store gem artifact
151+
uses: actions/upload-artifact@v4
152+
with:
153+
name: gem-${{ steps.gem_info.outputs.gem_version }}
154+
path: "*.gem"
155+
retention-days: 30
156+
157+
- name: Create build summary
158+
run: |
159+
echo "## Gem Built Successfully 💎" >> $GITHUB_STEP_SUMMARY
160+
echo "- **Version**: ${{ steps.gem_info.outputs.gem_version }}" >> $GITHUB_STEP_SUMMARY
161+
echo "- **File**: ${{ steps.gem_info.outputs.gem_file }}" >> $GITHUB_STEP_SUMMARY
162+
echo "- **Branch**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
163+
echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
164+
echo "" >> $GITHUB_STEP_SUMMARY
165+
echo "🚀 **Ready to publish!** Use the 'Manual Release' workflow to publish this gem." >> $GITHUB_STEP_SUMMARY
166+
167+
deploy:
168+
runs-on: ubuntu-latest
169+
needs: build
170+
if: github.ref == 'refs/heads/main'
171+
environment:
172+
name: production
173+
url: https://github.com/TwilightCoders/thaw/packages
174+
permissions:
175+
contents: read
176+
packages: write
177+
178+
steps:
179+
- uses: actions/checkout@v4
180+
181+
- name: Set up Ruby
182+
uses: ruby/setup-ruby@v1
183+
with:
184+
ruby-version: "3.3"
185+
bundler-cache: true
186+
187+
- name: Download gem artifact
188+
uses: actions/download-artifact@v4
189+
with:
190+
pattern: gem-*
191+
merge-multiple: true
192+
193+
- name: Show deployment details
194+
run: |
195+
echo "## 🚀 Ready to Deploy" >> $GITHUB_STEP_SUMMARY
196+
echo "**Gem**: $(ls *.gem)" >> $GITHUB_STEP_SUMMARY
197+
echo "**Branch**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
198+
echo "**Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
199+
echo "**Size**: $(ls -lh *.gem | awk '{print $5}')" >> $GITHUB_STEP_SUMMARY
200+
echo "" >> $GITHUB_STEP_SUMMARY
201+
echo "### Manual Approval Required" >> $GITHUB_STEP_SUMMARY
202+
echo "This deployment uses the \`production\` environment and can require manual approval." >> $GITHUB_STEP_SUMMARY
203+
echo "" >> $GITHUB_STEP_SUMMARY
204+
echo "**To enable manual approval:**" >> $GITHUB_STEP_SUMMARY
205+
echo "1. Go to **Settings** → **Environments** → **production**" >> $GITHUB_STEP_SUMMARY
206+
echo "2. Enable **Required reviewers** and add yourself" >> $GITHUB_STEP_SUMMARY
207+
echo "3. Optionally enable **Wait timer** for additional safety" >> $GITHUB_STEP_SUMMARY
208+
echo "" >> $GITHUB_STEP_SUMMARY
209+
echo "📖 **See:** [GitHub Docs - Reviewing Deployments](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-deployments/reviewing-deployments)" >> $GITHUB_STEP_SUMMARY
210+
echo "" >> $GITHUB_STEP_SUMMARY
211+
echo "Once configured, you'll get a **Review deployments** button to approve/reject releases." >> $GITHUB_STEP_SUMMARY
212+
213+
- name: Publish to GitHub Packages
214+
id: publish
215+
continue-on-error: true
216+
run: |
217+
mkdir -p ~/.gem
218+
cat << EOF > ~/.gem/credentials
219+
---
220+
:github: Bearer ${{ secrets.GITHUB_TOKEN }}
221+
EOF
222+
chmod 600 ~/.gem/credentials
223+
224+
# Try to publish, capturing output
225+
if gem push --key github --host https://rubygems.pkg.github.com/TwilightCoders *.gem 2>&1 | tee publish_output.log; then
226+
echo "success=true" >> $GITHUB_OUTPUT
227+
echo "message=Successfully published $(ls *.gem)" >> $GITHUB_OUTPUT
228+
else
229+
# Check if it's a version conflict (common scenario)
230+
if grep -q "already exists" publish_output.log || grep -q "Repushing of gem versions is not allowed" publish_output.log; then
231+
echo "success=false" >> $GITHUB_OUTPUT
232+
echo "message=Version $(ls *.gem) already exists in GitHub Packages - no action needed" >> $GITHUB_OUTPUT
233+
else
234+
echo "success=false" >> $GITHUB_OUTPUT
235+
echo "message=Failed to publish: $(cat publish_output.log)" >> $GITHUB_OUTPUT
236+
fi
237+
fi
238+
239+
- name: Deployment summary
240+
run: |
241+
if [ "${{ steps.publish.outputs.success }}" == "true" ]; then
242+
echo "## ✅ Deployment Complete" >> $GITHUB_STEP_SUMMARY
243+
echo "${{ steps.publish.outputs.message }}" >> $GITHUB_STEP_SUMMARY
244+
else
245+
echo "## ⚠️ Deployment Skipped" >> $GITHUB_STEP_SUMMARY
246+
echo "${{ steps.publish.outputs.message }}" >> $GITHUB_STEP_SUMMARY
247+
echo "" >> $GITHUB_STEP_SUMMARY
248+
echo "This is typically expected when the version already exists." >> $GITHUB_STEP_SUMMARY
249+
fi

0 commit comments

Comments
 (0)