Merge pull request #1252 from CodeForPhilly/staging #59
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: Publish Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20.8.1' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Create Tag | |
| uses: cycjimmy/[email protected] | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Read version number | |
| id: get_version | |
| run: | | |
| set -e | |
| echo "---------------------------------------------------------" | |
| if [ -s version.txt ]; then | |
| version=$(cat version.txt) | |
| echo "✅ New version detected: v$version" | |
| echo "---------------------------------------------------------" | |
| echo "version=${version}" >> $GITHUB_OUTPUT | |
| else | |
| echo "🚫 No version update detected. " | |
| echo " This indicates that there is no new release to publish." | |
| echo "---------------------------------------------------------" | |
| echo "version=" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Publish release notes | |
| if: steps.get_version.outputs.version != '' | |
| uses: actions/github-script@v7 | |
| env: | |
| NEW_VERSION: ${{ steps.get_version.outputs.version }} | |
| with: | |
| script: | | |
| (async () => { | |
| try { | |
| const newVersion = process.env.NEW_VERSION.trim(); | |
| const tagName = `v${newVersion}`; | |
| const response = await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: tagName, | |
| name: `Version ${newVersion}`, | |
| generate_release_notes: true, | |
| draft: false, | |
| prerelease: false | |
| }); | |
| const date = new Date().toLocaleDateString("en-US", { | |
| timeZone: "America/New_York", | |
| year: "numeric", | |
| month: "long", | |
| day: "numeric" | |
| }); | |
| const customHeader = `Release Notes for Version ${newVersion} - ${date}\n\n`; | |
| const updatedBody = customHeader + response.data.body; | |
| await github.rest.repos.updateRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: response.data.id, | |
| body: updatedBody, | |
| name: `Version ${newVersion}` | |
| }); | |
| console.log(`✅ Successfully published release notes for version ${newVersion}`); | |
| } catch (error) { | |
| console.error(`🚫 Failed to publish release notes: ${error}`); | |
| process.exit(1); | |
| } | |
| })(); |