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

Release: Support canary PRs #43

Merged
merged 11 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
88 changes: 88 additions & 0 deletions .github/workflows/canary-release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Publish canary release of PR
run-name: 'Canary release: PR #${{ github.event.pull_request.number }} at ${{ github.sha }}'

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- next-v2

env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 1

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

permissions:
pull-requests: write

jobs:
release-canary:
name: Release canary version
runs-on: ubuntu-latest
environment: canary-release
defaults:
run:
working-directory: scripts
steps:
- name: Checkout
uses: actions/checkout@v3

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

- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.yarn/berry/cache
key: yarn-v1-${{ hashFiles('scripts/yarn.lock') }}-${{ hashFiles('code/yarn.lock') }}
restore-keys: |
yarn-v1-${{ hashFiles('scripts/yarn.lock') }}-${{ hashFiles('code/yarn.lock') }}
yarn-v1-${{ hashFiles('scripts/yarn.lock') }}
yarn-v1

- name: Install dependencies
working-directory: .
run: yarn task --task=install --start-from=install

- name: Set version
id: version
run: |
SHORT_SHA=$(git rev-parse --short ${{ github.sha }})
yarn release:version --release-type prerelease --pre-id pr-${{ github.event.pull_request.number }}-$SHORT_SHA --verbose

- name: Publish v${{ steps.version.outputs.next-version }}
env:
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn release:publish --tag pr-${{ github.event.pull_request.number }} --verbose

- name: Create comment on PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment ${{ github.event.pull_request.number }}\
--repo "${{github.repository }}"\
--body "🚀 This pull request has been published as version \`${{ steps.version.outputs.next-version }}\` and with the tag \`pr-${{ github.event.pull_request.number }}\`.
[You can see it on the npm registry here](https://npmjs.com/package/@storybook/cli/v/${{ steps.version.outputs.next-version }})".

- name: Create failing comment on PR
if: failure()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment ${{ github.event.pull_request.number }}\
--repo "${{github.repository }}"\
--body "Failed to publish canary version of this pul request. See the failed workflow run at See run at: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"

# - name: Report failure to Discord
# if: failure()
# env:
# DISCORD_WEBHOOK: ${{ secrets.DISCORD_MONITORING_URL }}
# uses: Ilshidur/action-discord@master
# with:
# args: 'The GitHub Action for publishing version ${{ steps.version.outputs.current-version }} (triggered by ${{ github.triggering_actor }}) failed! See run at: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
14 changes: 6 additions & 8 deletions scripts/release/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import { execaCommand } from '../utils/exec';
program
.name('publish')
.description('publish all packages')
.option(
.requiredOption(
'-T, --tag <tag>',
'Specify which distribution tag to set for the version being published'
'Specify which distribution tag to set for the version being published. Required, since leaving it undefined would publish with the "latest" tag'
)
.option('-D, --dry-run', 'Do not publish, only output to shell', false)
.option('-V, --verbose', 'Enable verbose logging', false);

const optionsSchema = z
.object({
tag: z.string().optional(),
tag: z.string(),
verbose: z.boolean().optional(),
dryRun: z.boolean().optional(),
})
Expand All @@ -34,7 +34,7 @@ const optionsSchema = z
});

type Options = {
tag?: string;
tag: string;
verbose: boolean;
dryRun?: boolean;
};
Expand Down Expand Up @@ -122,14 +122,12 @@ const publishAllPackages = async ({
verbose,
dryRun,
}: {
tag?: string;
tag: string;
verbose?: boolean;
dryRun?: boolean;
}) => {
console.log(`📦 Publishing all packages...`);
const command = `yarn workspaces foreach --parallel --no-private --verbose npm publish --tolerate-republish ${
tag ? `--tag ${tag}` : ''
}`;
const command = `yarn workspaces foreach --parallel --no-private --verbose npm publish --tolerate-republish --tag ${tag}`;
if (verbose) {
console.log(`📦 Executing: ${command}`);
}
Expand Down