try fix publish betas v10 #61
This file contains 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: Build, Test for Main | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [opened, synchronize, reopened, labeled] | |
jobs: | |
build: | |
name: Build | |
strategy: | |
matrix: | |
os: | |
- ubuntu-latest | |
- macOS-latest | |
runs-on: ${{ matrix.os }} | |
timeout-minutes: 15 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- uses: pnpm/action-setup@v4 | |
with: | |
package_json_file: package.json | |
run_install: false | |
- name: Setup Node.js environment | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .nvmrc | |
cache: "pnpm" | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build | |
run: pnpm build | |
- name: Test | |
run: pnpm test | |
publish: | |
name: Publish to NPM or Create Version PR | |
needs: build | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Generate a token | |
uses: actions/create-github-app-token@v1 | |
id: generate-token | |
with: | |
# uses https://github.com/organizations/tinacms/settings/apps/release-bot-allow-prs-and-push | |
app-id: ${{ secrets.BOT_APP_ID }} | |
private-key: ${{ secrets.BOT_APP_SECRET }} | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ steps.generate-token.outputs.token || secrets.GITHUB_TOKEN }} | |
fetch-depth: 0 | |
- uses: pnpm/action-setup@v4 | |
with: | |
package_json_file: package.json | |
run_install: false | |
- name: Setup Node.js environment | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .nvmrc | |
cache: "pnpm" | |
registry-url: https://registry.npmjs.org | |
- name: Install dependencies | |
run: pnpm install | |
- name: Create Release Pull Request | |
id: changesets | |
uses: changesets/action@v1 | |
with: | |
version: pnpm run version | |
env: | |
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token || secrets.GITHUB_TOKEN }} | |
- name: Publish beta | |
if: steps.changesets.outputs.hasChangesets == 'true' | |
run: | | |
pnpm exec changeset version --snapshot | |
- uses: JS-DevTools/npm-publish@v3 | |
name: Publish to NPM | |
with: | |
access: public | |
tag: ${{ steps.changesets.outputs.hasChangesets == 'true' && 'beta' || 'latest' }} | |
token: ${{ secrets.NPM_AUTH_TOKEN }} | |
publish-pr: | |
name: Publish PR preview | |
needs: build | |
if: > | |
github.event_name == 'pull_request' && | |
contains(github.event.pull_request.labels.*.name, 'tagged') | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: pnpm/action-setup@v4 | |
with: | |
package_json_file: package.json | |
run_install: false | |
- name: Setup Node.js environment | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .nvmrc | |
cache: "pnpm" | |
registry-url: https://registry.npmjs.org | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build | |
run: pnpm build | |
- name: Publish tagged PR | |
run: | | |
pnpm exec changeset version --snapshot | |
- uses: JS-DevTools/npm-publish@v3 | |
name: Publish to NPM | |
with: | |
access: public | |
tag: ${{ github.head_ref || github.ref_name }} | |
token: ${{ secrets.NPM_AUTH_TOKEN }} |