Skip to content

Commit

Permalink
chore: add publish-unstable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
bapmrl committed Dec 21, 2023
1 parent 957cc8d commit 4a42dd8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/publish-unstable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish unstable
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
push:
branches: main
workflow_dispatch:
jobs:
publish-unstable:
name: Publish unstable
runs-on: ubuntu-latest
if: ${{ !startsWith(github.event.head_commit.message, 'release:') && !github.event.pull_request.draft }}
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.head_ref || github.ref }}
- name: Use Node.js
uses: ./.github/actions/setup-node
- name: Install dependencies
run: yarn install
- name: Run publish script
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
git config user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
git config user.name "${GITHUB_ACTOR}"
yarn publish unstable --tolerate-republish
13 changes: 5 additions & 8 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import {
readCurrentBranchHeadTags,
readCurrentBranchName,
readDefaultBranchName,
} from "./utils/gitUtils";
import {
fetchPackageVersionHistory,
Expand All @@ -22,9 +21,13 @@ import {

publish();

async function publish(): Promise<void> {
type Options = { defaultBranchName?: string };

async function publish(options?: Options): Promise<void> {
process.on("uncaughtException", handleUncaughtException);

const defaultBranchName = options?.defaultBranchName ?? "main";

// Parse the command-line arguments.
const args = mri<{ "dry-run": boolean; "tolerate-republish": boolean }>(
process.argv.slice(2),
Expand Down Expand Up @@ -120,12 +123,6 @@ async function publish(): Promise<void> {
`Invalid current branch name: \`${currentBranchName}\`. It must use GitHub's safe set of characters (see https://docs.github.com/en/get-started/using-git/dealing-with-special-characters-in-branch-and-tag-names#naming-branches-and-tags).`,
);
}
const defaultBranchName = await readDefaultBranchName();
if (defaultBranchName === undefined) {
throw new CommandError(
"There's no default branch set for the `origin` remote.",
);
}
const isOnDefaultBranch = currentBranchName === defaultBranchName;
if (mode === "stable" && !isOnDefaultBranch) {
throw new CommandError(
Expand Down
9 changes: 0 additions & 9 deletions scripts/utils/gitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,3 @@ export async function readCurrentBranchName(): Promise<string | undefined> {
const { stdout } = await exec("git", ["branch", "--show-current"]);
return stdout.length > 0 ? stdout : undefined;
}

export async function readDefaultBranchName(): Promise<string | undefined> {
const namespace = "refs/remotes/origin";
const { stdout } = await exec("git", [
...["rev-parse", "--quiet", "--symbolic-full-name", "--verify"],
`${namespace}/HEAD`,
]);
return stdout.length > 0 ? stdout.replace(`${namespace}/`, "") : undefined;
}

0 comments on commit 4a42dd8

Please sign in to comment.