New feature that needs preview #7
This file contains 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: Create a Snapshot Release | |
on: | |
workflow_dispatch: | |
issue_comment: | |
types: [created] | |
defaults: | |
run: | |
shell: bash | |
env: | |
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} | |
TURBO_TEAM: ${{ secrets.TURBO_TEAM }} | |
FORCE_COLOR: true | |
jobs: | |
snapshot-release: | |
name: Create a snapshot release of a pull request | |
if: ${{ github.repository_owner == 'lilnasy' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!preview') }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
id-token: write | |
issues: write | |
pull-requests: write | |
steps: | |
- name: "Check if user has admin access (only admins can publish snapshot releases)." | |
uses: "lannonbr/repo-permission-check-action@2.0.0" | |
with: | |
permission: "admin" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract the snapshot name from comment body | |
id: getSnapshotName | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const splitComment = context.payload.comment.body.split(' '); | |
splitComment.length !== 2 && (github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: 'Invalid comment format. Expected: "!preview <one-word-snapshot-name>"', | |
}) || core.setFailed('Invalid comment format. Expected: "!preview <one-word-snapshot-name>"')); | |
return splitComment[1].trim(); | |
result-encoding: string | |
- name: resolve pr refs | |
id: refs | |
uses: eficode/resolve-pr-refs@main | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ steps.refs.outputs.head_ref }} | |
fetch-depth: 0 | |
- run: git checkout main | |
- run: git checkout ${{ steps.refs.outputs.head_ref }} | |
- name: Setup PNPM | |
uses: pnpm/action-setup@v2 | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
registry-url: "https://registry.npmjs.org" | |
cache: "pnpm" | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build Packages | |
run: pnpm run build | |
- name: Bump Package Versions | |
id: changesets | |
run: | | |
pnpm exec changeset status --output changesets.output.json 2>&1 | |
pnpm exec changeset version --snapshot ${{ steps.getSnapshotName.outputs.result }} > changesets-version.output.txt 2>&1 | |
{ | |
echo 'result<<__EOF' | |
cat changesets.output.json | |
echo __EOF | |
} >> "$GITHUB_OUTPUT" | |
env: | |
# Needs access to run the script | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish Release | |
id: publish | |
run: | | |
pnpm run release --tag next--${{ steps.getSnapshotName.outputs.result }} > publish.output.txt 2>&1 | |
echo "Release complete" | |
cat publish.output.txt | |
{ | |
echo 'result<<__EOF' | |
cat publish.output.txt | |
echo __EOF | |
} >> "$GITHUB_OUTPUT" | |
env: | |
# Needs access to publish to npm | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Pull Request Notification | |
uses: actions/github-script@v6 | |
env: | |
RELEASES: ${{ steps.changesets.outputs.result }} | |
MESSAGE: ${{ steps.publish.outputs.result }} | |
with: | |
script: | | |
console.log(process.env.MESSAGE); | |
const changeset = JSON.parse(process.env.RELEASES); | |
const message = 'The following packages have been released:' | |
for (const release of changeset.releases) { | |
if (release.type === 'none') continue; | |
message += `\n- ${release.name}@${release.newVersion}`; | |
} | |
message += '\n'; | |
message += '<details><summary>Build Log</summary>\n\n```\n'; | |
message += process.env.message; | |
message += '\n```\n\n</details>'; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: '```\n' + process.env.MESSAGE + '\n```', | |
}) |