1- name : Build and Deploy
1+ name : Build and Release
22
33on :
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+
914jobs :
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
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
0 commit comments