Skip to content

Commit 07a51d4

Browse files
Add release management
1 parent 55d8b9a commit 07a51d4

File tree

4 files changed

+206
-4
lines changed

4 files changed

+206
-4
lines changed

.github/workflows/build.yml

Lines changed: 122 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
name: Build and Deploy
1+
name: Build and Release
22

33
on:
44
push:
55
branches: [ main ]
66
pull_request:
77
branches: [ main ]
88

9+
permissions:
10+
contents: write
11+
issues: write
12+
pull-requests: write
13+
914
jobs:
1015
build:
16+
name: Verify `trnmlp build` succeeds
1117
runs-on: ubuntu-latest
1218
steps:
1319
- name: Checkout repository
@@ -22,10 +28,120 @@ jobs:
2228
- name: Run trmnlp build
2329
run: bundle exec trmnlp build
2430

31+
check-secret:
32+
name: Check if `TRMNL_API_KEY` set
33+
runs-on: ubuntu-latest
34+
outputs:
35+
has-secret: ${{ steps.check.outputs.has-secret }}
36+
steps:
37+
- name: Check if TRMNL_API_KEY secret exists
38+
id: check
39+
env:
40+
TRMNL_API_KEY: ${{ secrets.TRMNL_API_KEY }}
41+
run: |
42+
if [ -n "$TRMNL_API_KEY" ]; then
43+
echo "has-secret=true" >> $GITHUB_OUTPUT
44+
else
45+
echo "No configured TRMNL_API_KEY, stopping."
46+
echo "has-secret=false" >> $GITHUB_OUTPUT
47+
fi
48+
49+
check-version:
50+
name: Check if VERSION is new
51+
needs: [check-secret, build]
52+
runs-on: ubuntu-latest
53+
if: github.ref == 'refs/heads/main' && needs.check-secret.outputs.has-secret == 'true'
54+
outputs:
55+
version: ${{ steps.version.outputs.version }}
56+
should-release: ${{ steps.check.outputs.should-release }}
57+
steps:
58+
- name: Checkout repository
59+
uses: actions/checkout@v4
60+
61+
- name: Read VERSION file
62+
id: version
63+
run: |
64+
VERSION=$(cat VERSION | tr -d '\n\r' | xargs)
65+
echo "version=$VERSION" >> $GITHUB_OUTPUT
66+
echo "Current version: $VERSION"
67+
68+
- name: Validate version format
69+
run: |
70+
VERSION="${{ steps.version.outputs.version }}"
71+
if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
72+
echo "Error: VERSION file must contain a valid semver format (e.g., 1.0.0)"
73+
exit 1
74+
fi
75+
76+
- name: Check if tag exists
77+
id: check
78+
run: |
79+
VERSION="${{ steps.version.outputs.version }}"
80+
if git ls-remote --tags origin | grep -q "refs/tags/v$VERSION$"; then
81+
echo "Tag v$VERSION already exists, skipping release"
82+
echo "should-release=false" >> $GITHUB_OUTPUT
83+
else
84+
echo "Tag v$VERSION does not exist, will create release"
85+
echo "should-release=true" >> $GITHUB_OUTPUT
86+
fi
87+
88+
create-release:
89+
name: Create a GitHub release
90+
needs: [check-secret, check-version]
91+
runs-on: ubuntu-latest
92+
if: needs.check-version.outputs.should-release == 'true' && needs.check-secret.outputs.has-secret == 'true'
93+
steps:
94+
- name: Checkout repository
95+
uses: actions/checkout@v4
96+
with:
97+
fetch-depth: 0 # Fetch full history for changelog generation
98+
99+
- name: Create tag
100+
run: |
101+
VERSION="${{ needs.check-version.outputs.version }}"
102+
git config user.name "github-actions[bot]"
103+
git config user.email "github-actions[bot]@users.noreply.github.com"
104+
git tag -a "v$VERSION" -m "Release v$VERSION"
105+
git push origin "v$VERSION"
106+
107+
- name: Generate release notes
108+
id: release-notes
109+
run: |
110+
VERSION="${{ needs.check-version.outputs.version }}"
111+
112+
# Get the previous tag
113+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
114+
115+
# Generate changelog
116+
if [ -n "$PREV_TAG" ]; then
117+
echo "## Changes since $PREV_TAG" > release_notes.md
118+
echo "" >> release_notes.md
119+
git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD >> release_notes.md
120+
else
121+
echo "## Initial Release" > release_notes.md
122+
echo "" >> release_notes.md
123+
echo "- Initial release of plugin" >> release_notes.md
124+
fi
125+
126+
echo "Release notes generated:"
127+
cat release_notes.md
128+
129+
- name: Create GitHub Release
130+
uses: softprops/action-gh-release@v2
131+
with:
132+
tag_name: v${{ needs.check-version.outputs.version }}
133+
name: Release v${{ needs.check-version.outputs.version }}
134+
body_path: release_notes.md
135+
draft: false
136+
prerelease: false
137+
env:
138+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139+
25140
deploy:
26-
needs: build
141+
name: Deploy to TRMNL
142+
needs: [check-secret, check-version, create-release]
27143
runs-on: ubuntu-latest
28-
if: github.ref == 'refs/heads/main'
144+
if: success() && needs.check-secret.outputs.has-secret == 'true'
29145
steps:
30146
- name: Checkout repository
31147
uses: actions/checkout@v4
@@ -47,4 +163,6 @@ jobs:
47163
EOF
48164
49165
- name: Run trmnlp push
50-
run: bundle exec trmnlp push --force
166+
run: |
167+
echo "Deploying version ${{ needs.check-version.outputs.version }}"
168+
bundle exec trmnlp push --force

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,37 @@ The script automatically creates a timestamped backup of the original settings f
3030
**Requirements:**
3131
- Ruby (built-in libraries only)
3232
- Internet connection to fetch data from PBS Kids API
33+
34+
### Releasing
35+
36+
This project uses automated releases based on the `VERSION` file. To create a new release:
37+
38+
1. Update the version using the bump script:
39+
```bash
40+
./bin/bump-version [major|minor|patch]
41+
```
42+
43+
2. Commit and push the version change:
44+
```bash
45+
git add VERSION
46+
git commit -m "Bump version to X.Y.Z"
47+
git push origin main
48+
```
49+
50+
3. The GitHub Action will automatically:
51+
- Create a git tag for the new version
52+
- Generate release notes from commits
53+
- Create a GitHub release
54+
- Deploy to TRMNL using `trmnlp push`
55+
56+
### Manual Development
57+
58+
For local development and testing:
59+
60+
```bash
61+
# Run development server
62+
./bin/dev
63+
64+
# Push to TRMNL (requires API key configuration)
65+
trmnlp push
66+
```

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

bin/bump-version

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# Simple script to bump version in VERSION file
4+
# Usage: ./bump-version.sh [major|minor|patch]
5+
6+
set -e
7+
8+
CURRENT_VERSION=$(cat VERSION | tr -d '\n\r' | xargs)
9+
TYPE=${1:-patch}
10+
11+
echo "Current version: $CURRENT_VERSION"
12+
13+
# Split version into parts
14+
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
15+
MAJOR=${VERSION_PARTS[0]}
16+
MINOR=${VERSION_PARTS[1]}
17+
PATCH=${VERSION_PARTS[2]}
18+
19+
case $TYPE in
20+
major)
21+
MAJOR=$((MAJOR + 1))
22+
MINOR=0
23+
PATCH=0
24+
;;
25+
minor)
26+
MINOR=$((MINOR + 1))
27+
PATCH=0
28+
;;
29+
patch)
30+
PATCH=$((PATCH + 1))
31+
;;
32+
*)
33+
echo "Usage: $0 [major|minor|patch]"
34+
echo " major: Increment major version (x.0.0)"
35+
echo " minor: Increment minor version (x.y.0)"
36+
echo " patch: Increment patch version (x.y.z)"
37+
exit 1
38+
;;
39+
esac
40+
41+
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
42+
echo "$NEW_VERSION" > VERSION
43+
44+
echo "Version bumped to: $NEW_VERSION"
45+
echo ""
46+
echo "Next steps:"
47+
echo "1. Review your changes"
48+
echo "2. Commit with: git add VERSION && git commit -m 'Bump version to $NEW_VERSION'"
49+
echo "3. Push to trigger release: git push origin main"

0 commit comments

Comments
 (0)