Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new preview release action #4483

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Release

on:
push:
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/snapshot-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Create a Snapshot Release

on:
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/[email protected]"
with:
permission: "admin"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.ref }}

- name: Setup PNPM
uses: pnpm/[email protected]

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Build Packages
run: pnpm run build

- name: Extract the snapshot name from comment body
id: getSnapshotName
uses: actions/github-script@v6
env:
MESSAGE: ${{ steps.changesets.outputs.publish }}
with:
script: |
const splitComment = github.event.comment.body.split(' ');
splitComment.length !== 2 && (github.rest.issues.createComment({
issue_number: process.env.ISSUE_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Invalid comment format. Expected: "!preview <one-word-snapshot-name>"',
}) || exit 1);
return splitComment[1].trim();
result-encoding: string

- name: Bump Package Versions
id: changesets
run: npx changeset version --snapshot ${{ steps.getSnapshotName.outputs.result }}
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 }}
env:
# Needs access to publish to npm
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Pull Request Notification
uses: actions/github-script@v6
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
MESSAGE: ${{ steps.changesets.outputs.publish }}
with:
script: |
console.log(process.env);
github.rest.issues.createComment({
issue_number: process.env.ISSUE_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
body: '```\n' + process.env.MESSAGE + '\n```',
})