Publish Packages #54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Packages | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| mode: | |
| description: "Publish mode (canary or stable)" | |
| required: true | |
| default: "stable" | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: ${{ github.event.inputs.mode == 'canary' && 'canary' || 'master' }} | |
| - name: Setup pnpm | |
| uses: pnpm/[email protected] | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 22 | |
| cache: "pnpm" | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Verify NPM_TOKEN | |
| run: | | |
| if [ -z "${{ secrets.NPM_TOKEN }}" ]; then | |
| echo "NPM_TOKEN is not set. Please configure it in the repository secrets." | |
| exit 1 | |
| fi | |
| - name: Verify versions | |
| run: pnpm scripts:uv | |
| - name: Build packages | |
| run: pnpm build | |
| - name: Prepare packages | |
| run: | | |
| if [ "${{ github.event.inputs.mode }}" == "canary" ]; then | |
| pnpm scripts:prepare --canary | |
| else | |
| pnpm scripts:prepare | |
| fi | |
| - name: Publish packages | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: | | |
| echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc | |
| pnpm m ls --json --depth=-1 | jq -r '.[].path' | grep '/packages/' | while read -r package; do | |
| echo "Publishing package: $package" | |
| cd "$package" | |
| if [ "${{ github.event.inputs.mode }}" == "canary" ]; then | |
| npm publish --access public --tag canary --provenance --no-git-checks --userconfig ~/.npmrc | |
| else | |
| npm publish --access public --provenance --no-git-checks --userconfig ~/.npmrc | |
| fi | |
| cd - | |
| done | |
| - name: Create GitHub Release | |
| if: success() | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAT }} | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| if [ "${{ github.event.inputs.mode }}" == "canary" ]; then | |
| IS_PRERELEASE=true | |
| else | |
| IS_PRERELEASE=false | |
| fi | |
| TAG="v$VERSION" | |
| DESCRIPTION="Automated release publish for ContentKit $TAG" | |
| gh release create "$TAG" --title "$TAG" --notes "$DESCRIPTION" --prerelease=$IS_PRERELEASE |