2022-09-12 21:21:20 +00:00
|
|
|
name: Create a Snapshot Release
|
|
|
|
|
|
|
|
on:
|
2023-03-01 14:02:35 +00:00
|
|
|
workflow_dispatch:
|
2022-09-12 21:21:20 +00:00
|
|
|
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 == 'withastro' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!preview') }}
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
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 }}
|
2023-02-24 15:52:43 +00:00
|
|
|
|
2022-09-12 21:25:01 +00:00
|
|
|
- name: Extract the snapshot name from comment body
|
|
|
|
id: getSnapshotName
|
|
|
|
uses: actions/github-script@v6
|
|
|
|
with:
|
2023-02-24 15:52:43 +00:00
|
|
|
script: |
|
2022-09-12 21:34:50 +00:00
|
|
|
const splitComment = context.payload.comment.body.split(' ');
|
2022-09-12 21:25:01 +00:00
|
|
|
splitComment.length !== 2 && (github.rest.issues.createComment({
|
2022-09-12 21:30:58 +00:00
|
|
|
issue_number: context.issue.number,
|
2022-09-12 21:25:01 +00:00
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
body: 'Invalid comment format. Expected: "!preview <one-word-snapshot-name>"',
|
2022-09-12 21:30:58 +00:00
|
|
|
}) || core.setFailed('Invalid comment format. Expected: "!preview <one-word-snapshot-name>"'));
|
2022-09-12 21:25:01 +00:00
|
|
|
return splitComment[1].trim();
|
|
|
|
result-encoding: string
|
2022-09-13 20:48:39 +00:00
|
|
|
|
|
|
|
- name: resolve pr refs
|
|
|
|
id: refs
|
|
|
|
uses: eficode/resolve-pr-refs@main
|
|
|
|
with:
|
|
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
2023-02-24 15:52:43 +00:00
|
|
|
|
2022-09-12 21:21:20 +00:00
|
|
|
- uses: actions/checkout@v3
|
|
|
|
with:
|
2022-09-13 20:56:36 +00:00
|
|
|
ref: ${{ steps.refs.outputs.head_ref }}
|
2022-09-12 21:21:20 +00:00
|
|
|
|
2022-10-28 18:36:50 +00:00
|
|
|
- name: Setup PNPM
|
2023-02-24 15:52:43 +00:00
|
|
|
uses: pnpm/action-setup@v2
|
2022-10-28 18:36:50 +00:00
|
|
|
|
|
|
|
- name: Setup Node
|
|
|
|
uses: actions/setup-node@v3
|
|
|
|
with:
|
2023-07-24 18:47:07 +00:00
|
|
|
node-version: 18
|
2023-02-24 15:52:43 +00:00
|
|
|
registry-url: "https://registry.npmjs.org"
|
|
|
|
cache: "pnpm"
|
2022-10-28 18:36:50 +00:00
|
|
|
|
|
|
|
- name: Install dependencies
|
|
|
|
run: pnpm install
|
2022-09-12 21:21:20 +00:00
|
|
|
|
|
|
|
- name: Build Packages
|
|
|
|
run: pnpm run build
|
|
|
|
|
|
|
|
- name: Bump Package Versions
|
|
|
|
id: changesets
|
2022-09-13 21:56:16 +00:00
|
|
|
run: |
|
|
|
|
pnpm exec changeset version --snapshot ${{ steps.getSnapshotName.outputs.result }} > changesets.output.txt 2>&1
|
|
|
|
echo ::set-output name=result::`cat changesets.output.txt`
|
2022-09-12 21:21:20 +00:00
|
|
|
env:
|
|
|
|
# Needs access to run the script
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
2022-09-13 21:07:32 +00:00
|
|
|
- name: Publish Release
|
|
|
|
id: publish
|
2022-09-13 21:56:16 +00:00
|
|
|
run: |
|
2023-10-06 19:50:36 +00:00
|
|
|
pnpm run release --tag next--${{ steps.getSnapshotName.outputs.result }}
|
2023-10-05 18:14:05 +00:00
|
|
|
echo "Release complete"
|
2022-09-13 21:07:32 +00:00
|
|
|
env:
|
|
|
|
# Needs access to publish to npm
|
|
|
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
2022-09-13 21:43:53 +00:00
|
|
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
2022-09-12 21:21:20 +00:00
|
|
|
|
|
|
|
- name: Pull Request Notification
|
|
|
|
uses: actions/github-script@v6
|
|
|
|
env:
|
2022-09-13 21:07:32 +00:00
|
|
|
MESSAGE: ${{ steps.publish.outputs.result }}
|
2022-09-12 21:21:20 +00:00
|
|
|
with:
|
|
|
|
script: |
|
2022-09-12 21:30:58 +00:00
|
|
|
console.log(process.env.MESSAGE);
|
2022-09-12 21:21:20 +00:00
|
|
|
github.rest.issues.createComment({
|
2022-09-12 21:30:58 +00:00
|
|
|
issue_number: context.issue.number,
|
2022-09-12 21:21:20 +00:00
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
body: '```\n' + process.env.MESSAGE + '\n```',
|
|
|
|
})
|