Bump version to 1.2.3 #25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Release | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| permissions: | |
| contents: write | |
| issues: write | |
| pull-requests: write | |
| deployments: write | |
| jobs: | |
| build: | |
| name: Verify `trnmlp build` succeeds | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Set up Ruby | |
| id: setup-ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: '3.4' | |
| bundler-cache: true | |
| - name: Resolve RubyGems user dir | |
| id: gemdir | |
| run: | | |
| set -euo pipefail | |
| GEM_USER_DIR="$(ruby -r rubygems -e 'print Gem.user_dir')" | |
| echo "dir=$GEM_USER_DIR" >> "$GITHUB_OUTPUT" | |
| echo "$GEM_USER_DIR/bin" >> "$GITHUB_PATH" | |
| - name: Cache trmnlp gem | |
| uses: actions/cache@v5 | |
| with: | |
| path: ${{ steps.gemdir.outputs.dir }} | |
| key: ${{ runner.os }}-ruby-${{ steps.setup-ruby.outputs.ruby-version }}-trmnl-preview-v1 | |
| - name: Install trmnlp | |
| run: | | |
| set -euo pipefail | |
| if ! command -v trmnlp >/dev/null 2>&1; then | |
| gem install --user-install trmnl_preview -N | |
| fi | |
| - name: Run trmnlp build | |
| run: trmnlp build | |
| check-secret: | |
| name: Check if `TRMNL_API_KEY` set | |
| runs-on: ubuntu-latest | |
| outputs: | |
| has-secret: ${{ steps.check.outputs.has-secret }} | |
| steps: | |
| - name: Check if TRMNL_API_KEY secret exists | |
| id: check | |
| env: | |
| TRMNL_API_KEY: ${{ secrets.TRMNL_API_KEY }} | |
| run: | | |
| if [ -n "$TRMNL_API_KEY" ]; then | |
| echo "has-secret=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No configured TRMNL_API_KEY, stopping." | |
| echo "has-secret=false" >> $GITHUB_OUTPUT | |
| fi | |
| check-version: | |
| name: Check if VERSION is new | |
| needs: [check-secret, build] | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' && needs.check-secret.outputs.has-secret == 'true' | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| should-release: ${{ steps.check.outputs.should-release }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Read VERSION file | |
| id: version | |
| run: | | |
| VERSION=$(cat VERSION | tr -d '\n\r' | xargs) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Current version: $VERSION" | |
| - name: Validate version format | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Error: VERSION file must contain a valid semver format (e.g., 1.0.0)" | |
| exit 1 | |
| fi | |
| - name: Check if tag exists | |
| id: check | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| if git ls-remote --tags origin | grep -q "refs/tags/v$VERSION$"; then | |
| echo "Tag v$VERSION already exists, skipping release" | |
| echo "should-release=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Tag v$VERSION does not exist, will create release" | |
| echo "should-release=true" >> $GITHUB_OUTPUT | |
| fi | |
| create-release: | |
| name: Create a GitHub release | |
| needs: [check-secret, check-version] | |
| runs-on: ubuntu-latest | |
| if: needs.check-version.outputs.should-release == 'true' && needs.check-secret.outputs.has-secret == 'true' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 # Fetch full history for changelog generation | |
| - name: Create tag | |
| run: | | |
| VERSION="${{ needs.check-version.outputs.version }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "v$VERSION" -m "Release v$VERSION" | |
| git push origin "v$VERSION" | |
| - name: Generate release notes | |
| id: release-notes | |
| run: | | |
| VERSION="${{ needs.check-version.outputs.version }}" | |
| # Get the previous tag | |
| PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| # Generate changelog | |
| if [ -n "$PREV_TAG" ]; then | |
| echo "## Changes since $PREV_TAG" > release_notes.md | |
| echo "" >> release_notes.md | |
| git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD >> release_notes.md | |
| else | |
| echo "## Initial Release" > release_notes.md | |
| echo "" >> release_notes.md | |
| echo "- Initial release of plugin" >> release_notes.md | |
| fi | |
| echo "Release notes generated:" | |
| cat release_notes.md | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v3 | |
| with: | |
| tag_name: v${{ needs.check-version.outputs.version }} | |
| name: Release v${{ needs.check-version.outputs.version }} | |
| body_path: release_notes.md | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| deploy: | |
| name: Deploy to TRMNL | |
| needs: [check-secret, check-version, create-release] | |
| runs-on: ubuntu-latest | |
| if: success() && needs.check-secret.outputs.has-secret == 'true' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Set up Ruby | |
| id: setup-ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: '3.4' | |
| bundler-cache: true | |
| - name: Resolve RubyGems user dir | |
| id: gemdir | |
| run: | | |
| set -euo pipefail | |
| GEM_USER_DIR="$(ruby -r rubygems -e 'print Gem.user_dir')" | |
| echo "dir=$GEM_USER_DIR" >> "$GITHUB_OUTPUT" | |
| echo "$GEM_USER_DIR/bin" >> "$GITHUB_PATH" | |
| - name: Cache trmnlp gem | |
| uses: actions/cache@v5 | |
| with: | |
| path: ${{ steps.gemdir.outputs.dir }} | |
| key: ${{ runner.os }}-ruby-${{ steps.setup-ruby.outputs.ruby-version }}-trmnl-preview-v1 | |
| - name: Install trmnlp | |
| run: | | |
| set -euo pipefail | |
| if ! command -v trmnlp >/dev/null 2>&1; then | |
| gem install --user-install trmnl_preview -N | |
| fi | |
| - name: Create trmnlp config directory | |
| run: mkdir -p ~/.config/trmnlp | |
| - name: Create trmnlp config file | |
| run: | | |
| cat > ~/.config/trmnlp/config.yml << EOF | |
| --- | |
| api_key: ${{ secrets.TRMNL_API_KEY }} | |
| EOF | |
| - name: Create GitHub deployment | |
| id: create_deployment | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const version = `${{ needs.check-version.outputs.version }}`; | |
| const deployment = await github.rest.repos.createDeployment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| ref: context.sha, | |
| environment: 'production', | |
| description: `Deploy version ${version} via trmnlp push`, | |
| auto_merge: false, | |
| required_contexts: [], | |
| transient_environment: false, | |
| production_environment: true, | |
| }); | |
| core.setOutput('deployment-id', String(deployment.data.id)); | |
| - name: Mark deployment in progress | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| await github.rest.repos.createDeploymentStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| deployment_id: Number(`${{ steps.create_deployment.outputs.deployment-id }}`), | |
| state: 'in_progress', | |
| description: 'Running trmnlp push', | |
| environment: 'production', | |
| }); | |
| - name: Run trmnlp push | |
| id: push | |
| continue-on-error: true | |
| run: | | |
| echo "Deploying version ${{ needs.check-version.outputs.version }}" | |
| trmnlp push --force | |
| - name: Mark deployment success | |
| if: steps.push.outcome == 'success' | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| await github.rest.repos.createDeploymentStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| deployment_id: Number(`${{ steps.create_deployment.outputs.deployment-id }}`), | |
| state: 'success', | |
| description: 'Deployment completed', | |
| environment: 'production', | |
| }); | |
| - name: Mark deployment failure | |
| if: steps.push.outcome == 'failure' | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| await github.rest.repos.createDeploymentStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| deployment_id: Number(`${{ steps.create_deployment.outputs.deployment-id }}`), | |
| state: 'failure', | |
| description: 'Deployment failed', | |
| environment: 'production', | |
| }); | |
| - name: Fail job when push fails | |
| if: steps.push.outcome == 'failure' | |
| run: exit 1 |