|
| 1 | +name: Release Please |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + release-please: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + release_created: ${{ steps.release.outputs.release_created }} |
| 17 | + tag_name: ${{ steps.release.outputs.tag_name }} |
| 18 | + version: ${{ steps.release.outputs.version }} |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: googleapis/release-please-action@v4 |
| 22 | + id: release |
| 23 | + with: |
| 24 | + release-type: simple |
| 25 | + package-name: wave-notes-setup |
| 26 | + |
| 27 | + # Run tests and create GitHub release with install instructions |
| 28 | + publish-release: |
| 29 | + needs: release-please |
| 30 | + if: ${{ needs.release-please.outputs.release_created }} |
| 31 | + runs-on: macos-latest |
| 32 | + |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - name: Install test tools |
| 37 | + run: brew install bats-core shellcheck |
| 38 | + |
| 39 | + - name: Run ShellCheck |
| 40 | + run: shellcheck install.sh uninstall.sh |
| 41 | + |
| 42 | + - name: Run tests |
| 43 | + run: bats test/*.bats |
| 44 | + |
| 45 | + - name: Calculate SHA256 |
| 46 | + id: sha256 |
| 47 | + run: | |
| 48 | + VERSION="${{ needs.release-please.outputs.tag_name }}" |
| 49 | + TARBALL_URL="https://github.com/${{ github.repository }}/archive/${VERSION}.tar.gz" |
| 50 | + curl -sL "$TARBALL_URL" -o release.tar.gz |
| 51 | + SHA256=$(shasum -a 256 release.tar.gz | cut -d' ' -f1) |
| 52 | + echo "sha256=$SHA256" >> $GITHUB_OUTPUT |
| 53 | +
|
| 54 | + - name: Update release notes |
| 55 | + uses: actions/github-script@v7 |
| 56 | + env: |
| 57 | + VERSION: ${{ needs.release-please.outputs.tag_name }} |
| 58 | + SHA256: ${{ steps.sha256.outputs.sha256 }} |
| 59 | + with: |
| 60 | + script: | |
| 61 | + const { VERSION, SHA256 } = process.env; |
| 62 | +
|
| 63 | + // Get the existing release |
| 64 | + const { data: release } = await github.rest.repos.getReleaseByTag({ |
| 65 | + owner: context.repo.owner, |
| 66 | + repo: context.repo.repo, |
| 67 | + tag: VERSION |
| 68 | + }); |
| 69 | +
|
| 70 | + // Append installation instructions |
| 71 | + const installInstructions = ` |
| 72 | +
|
| 73 | + ## Installation |
| 74 | +
|
| 75 | + ### Homebrew (Recommended) |
| 76 | + \`\`\`bash |
| 77 | + brew tap qbandev/wave-notes-setup |
| 78 | + brew install wave-notes-setup |
| 79 | + wave-notes-setup |
| 80 | + \`\`\` |
| 81 | +
|
| 82 | + ### curl |
| 83 | + \`\`\`bash |
| 84 | + curl -fsSL https://raw.githubusercontent.com/qbandev/wave-notes-setup/${VERSION}/install.sh | bash |
| 85 | + \`\`\` |
| 86 | +
|
| 87 | + ### Manual |
| 88 | + \`\`\`bash |
| 89 | + git clone https://github.com/qbandev/wave-notes-setup.git |
| 90 | + cd wave-notes-setup |
| 91 | + git checkout ${VERSION} |
| 92 | + ./install.sh |
| 93 | + \`\`\` |
| 94 | +
|
| 95 | + ## Homebrew Formula Update |
| 96 | +
|
| 97 | + Update \`Formula/wave-notes-setup.rb\`: |
| 98 | + \`\`\`ruby |
| 99 | + url "https://github.com/qbandev/wave-notes-setup/archive/${VERSION}.tar.gz" |
| 100 | + sha256 "${SHA256}" |
| 101 | + \`\`\` |
| 102 | + `; |
| 103 | +
|
| 104 | + await github.rest.repos.updateRelease({ |
| 105 | + owner: context.repo.owner, |
| 106 | + repo: context.repo.repo, |
| 107 | + release_id: release.id, |
| 108 | + body: release.body + installInstructions |
| 109 | + }); |
| 110 | +
|
| 111 | + console.log(`Release ${VERSION} updated with install instructions`); |
| 112 | + console.log(`SHA256 for Homebrew: ${SHA256}`); |
| 113 | +
|
| 114 | + # Notify about formula update needed |
| 115 | + notify-homebrew: |
| 116 | + needs: [release-please, publish-release] |
| 117 | + if: ${{ needs.release-please.outputs.release_created }} |
| 118 | + runs-on: ubuntu-latest |
| 119 | + |
| 120 | + steps: |
| 121 | + - name: Create issue for Homebrew update |
| 122 | + uses: actions/github-script@v7 |
| 123 | + env: |
| 124 | + VERSION: ${{ needs.release-please.outputs.tag_name }} |
| 125 | + with: |
| 126 | + script: | |
| 127 | + const version = process.env.VERSION; |
| 128 | +
|
| 129 | + // Check if issue already exists |
| 130 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 131 | + owner: context.repo.owner, |
| 132 | + repo: context.repo.repo, |
| 133 | + state: 'open', |
| 134 | + labels: 'homebrew,release' |
| 135 | + }); |
| 136 | +
|
| 137 | + const existingIssue = issues.find(i => i.title.includes(version)); |
| 138 | + if (existingIssue) { |
| 139 | + console.log('Issue already exists for this version'); |
| 140 | + return; |
| 141 | + } |
| 142 | +
|
| 143 | + await github.rest.issues.create({ |
| 144 | + owner: context.repo.owner, |
| 145 | + repo: context.repo.repo, |
| 146 | + title: `Update Homebrew formula for ${version}`, |
| 147 | + body: `A new release ${version} has been published. |
| 148 | +
|
| 149 | +## Action Required |
| 150 | + |
| 151 | +Update the Homebrew formula with the new SHA256 from the release notes. |
| 152 | + |
| 153 | +1. Go to [Releases](https://github.com/${context.repo.owner}/${context.repo.repo}/releases/tag/${version}) |
| 154 | +2. Copy the SHA256 value |
| 155 | +3. Update \`Formula/wave-notes-setup.rb\`: |
| 156 | + - Update the \`url\` to point to ${version} |
| 157 | + - Update the \`sha256\` value |
| 158 | +4. Commit and push the changes |
| 159 | +5. Close this issue |
| 160 | + |
| 161 | +This issue was automatically created by the release workflow.`, |
| 162 | + labels: ['homebrew', 'release'] |
| 163 | + }); |
0 commit comments