Skip to content
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
110 changes: 110 additions & 0 deletions .github/workflows/publish-package-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Package Release

on:
push:
branches:
- main

env:
GH_PACKAGES_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}

permissions:
# Enable the use of OIDC for trusted publishing and npm provenance
id-token: write
# Enable the use of GitHub Packages registry
packages: write
# Enable `semantic-release` to publish a GitHub release and push commits
contents: write
# Enable `semantic-release` to post comments on issues
issues: write
# Enable `semantic-release` to post comments on pull requests
pull-requests: write

# The release workflow involves many crucial steps that once triggered shouldn't be cancelled until
# finished, otherwise we might end up in an inconsistent state (e.g., published to GitHub Packages
# but not npm), so new workflow runs are queued until the previous one has completely finished.
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

jobs:
release-and-publish:
name: Release & Publish
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Generate release bot token
id: release-bot
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.DOIST_RELEASE_BOT_ID }}
private-key: ${{ secrets.DOIST_RELEASE_BOT_PRIVATE_KEY }}
permission-contents: write
permission-issues: write
permission-pull-requests: write

- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ steps.release-bot.outputs.token }}
fetch-depth: 0

- name: Prepare Node.js environment
uses: actions/setup-node@v6
with:
cache: npm
node-version-file: .node-version

- name: Cache project 'node_modules' directory
id: node-modules-cache
uses: actions/cache@v5
with:
key: node-modules-cache-${{ hashFiles('**/package-lock.json', '**/.node-version', 'patches/**') }}
path: node_modules/

- name: Install project npm dependencies
if: ${{ steps.node-modules-cache.outputs.cache-hit != 'true' }}
run: |
npm ci

- name: Build package
run: |
npm run build

# The Node.js environment is prepared based on the `.npmrc` file in the repo, which
# configures Doist scoped packages to use the public npm registry with OIDC
# authentication for the initial `semantic-release` publish, after which we remove the
# Doist registry configuration, and prepare the Node.js environment for the GitHub
# Packages registry, providing a predictable release workflow for both registries.
- name: Publish package to public npm registry
id: semantic-release
run: |
npx semantic-release
env:
GITHUB_TOKEN: ${{ steps.release-bot.outputs.token }}
GIT_AUTHOR_EMAIL: doistbot@users.noreply.github.com
GIT_AUTHOR_NAME: Doist Bot
GIT_COMMITTER_EMAIL: doistbot@users.noreply.github.com
GIT_COMMITTER_NAME: Doist Bot

- name: Remove Doist registry configuration from `.npmrc`
if: ${{ steps.semantic-release.outputs.package-published == 'true' }}
run: |
npm config delete @doist:registry --location=project

- name: Prepare Node.js environment for GitHub Packages registry
if: ${{ steps.semantic-release.outputs.package-published == 'true' }}
uses: actions/setup-node@v6
with:
cache: npm
node-version-file: .node-version
registry-url: https://npm.pkg.github.com/
scope: '@doist'

- name: Publish package to private GitHub Packages registry
if: ${{ steps.semantic-release.outputs.package-published == 'true' }}
run: |
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
115 changes: 0 additions & 115 deletions .github/workflows/release.yml

This file was deleted.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"**/*.css"
],
"publishConfig": {
"access": "public",
"provenance": true
"access": "public"
},
"files": [
"CHANGELOG.md",
Expand Down Expand Up @@ -55,8 +54,7 @@
"lint": "eslint --format codeframe --cache --ext js,jsx,ts,tsx ./",
"storybook": "start-storybook -p 6006",
"prettify": "prettier --write \"./**/*.{js,jsx,ts,tsx,json,css,scss,less,md,mdx}\"",
"plop": "plop",
"prepublishOnly": "npm run build && npm test"
"plop": "plop"
},
"peerDependencies": {
"@ariakit/react": "~0.4.19",
Expand Down
9 changes: 9 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,14 @@ export default {
},
],
'@semantic-release/github',
[
'@semantic-release/exec',
{
verifyConditionsCmd:
'if [ -n "$GITHUB_OUTPUT" ]; then echo "package-published=false" >> "$GITHUB_OUTPUT"; fi',
successCmd:
'if [ -n "$GITHUB_OUTPUT" ]; then echo "package-published=true" >> "$GITHUB_OUTPUT"; fi',
},
],
],
}
Loading