|
| 1 | +# Created using @tscircuit/plop (npm install -g @tscircuit/plop) |
| 2 | +name: Publish to npm |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - '!version-bumps/**' |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +env: |
| 11 | + UPSTREAM_REPOS: "" # comma-separated list, e.g. "eval,tscircuit,docs" |
| 12 | + UPSTREAM_PACKAGES_TO_UPDATE: "" # comma-separated list, e.g. "@tscircuit/core,@tscircuit/protos" |
| 13 | + |
| 14 | +jobs: |
| 15 | + publish: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - name: Setup bun |
| 20 | + uses: oven-sh/setup-bun@v2 |
| 21 | + with: |
| 22 | + bun-version: latest |
| 23 | + - uses: actions/setup-node@v4 |
| 24 | + with: |
| 25 | + node-version: 20 |
| 26 | + registry-url: https://registry.npmjs.org/ |
| 27 | + - run: npm install -g pver |
| 28 | + - run: bun install --frozen-lockfile |
| 29 | + - run: bun run build |
| 30 | + - run: pver release --no-push-main |
| 31 | + env: |
| 32 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 33 | + GITHUB_TOKEN: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }} |
| 34 | + |
| 35 | + - name: Get package version |
| 36 | + id: package-version |
| 37 | + run: | |
| 38 | + VERSION=$(node -p "require('./package.json').version") |
| 39 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 40 | +
|
| 41 | +
|
| 42 | + - name: Create Pull Request |
| 43 | + id: create-pr |
| 44 | + uses: peter-evans/create-pull-request@v6 |
| 45 | + with: |
| 46 | + commit-message: "chore: bump version" |
| 47 | + title: "chore: bump version to v${{ steps.package-version.outputs.version }}" |
| 48 | + body: "Automated package update" |
| 49 | + branch: version-bumps/v${{ steps.package-version.outputs.version }} |
| 50 | + base: main |
| 51 | + token: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }} |
| 52 | + committer: tscircuitbot <githubbot@tscircuit.com> |
| 53 | + author: tscircuitbot <githubbot@tscircuit.com> |
| 54 | + |
| 55 | + - name: Enable auto-merge |
| 56 | + if: steps.create-pr.outputs.pull-request-number != '' |
| 57 | + run: | |
| 58 | + gh pr merge ${{ steps.create-pr.outputs.pull-request-number }} --auto --squash --delete-branch |
| 59 | + env: |
| 60 | + GH_TOKEN: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }} |
| 61 | + |
| 62 | + - name: Trigger upstream repo updates |
| 63 | + if: env.UPSTREAM_REPOS && env.UPSTREAM_PACKAGES_TO_UPDATE |
| 64 | + run: | |
| 65 | + IFS=',' read -ra REPOS <<< "${{ env.UPSTREAM_REPOS }}" |
| 66 | + for repo in "${REPOS[@]}"; do |
| 67 | + if [[ -n "$repo" ]]; then |
| 68 | + echo "Triggering update for repo: $repo" |
| 69 | + curl -X POST \ |
| 70 | + -H "Accept: application/vnd.github.v3+json" \ |
| 71 | + -H "Authorization: token ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}" \ |
| 72 | + -H "Content-Type: application/json" \ |
| 73 | + "https://api.github.com/repos/tscircuit/$repo/actions/workflows/update-package.yml/dispatches" \ |
| 74 | + -d "{\"ref\":\"main\",\"inputs\":{\"package_names\":\"${{ env.UPSTREAM_PACKAGES_TO_UPDATE }}\"}}" |
| 75 | + fi |
| 76 | + done |
| 77 | + - name: Notify release-tracker of version update |
| 78 | + # Continue-on-error just in case the tracker is down |
| 79 | + continue-on-error: true |
| 80 | + run: | |
| 81 | + VERSION=$(node -p "require('./package.json').version") |
| 82 | + PACKAGE_JSON=$(cat package.json) |
| 83 | + curl -X POST https://release-tracker.tscircuit.com/release_events/create \ |
| 84 | + -H "Content-Type: application/json" \ |
| 85 | + -d "{ |
| 86 | + \"event\": { |
| 87 | + \"event_type\": \"versions_updated\", |
| 88 | + \"repo\": \"tscircuit/circuit-json-to-kicad\", |
| 89 | + \"version\": \"$VERSION\", |
| 90 | + \"package_json\": $PACKAGE_JSON |
| 91 | + } |
| 92 | + }" |
0 commit comments