|
| 1 | +name: Publish NPM Package |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Version bump type" |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - patch |
| 12 | + - minor |
| 13 | + - major |
| 14 | + - prerelease |
| 15 | + default: patch |
| 16 | + custom_version: |
| 17 | + description: "Custom version (optional, overrides version type)" |
| 18 | + required: false |
| 19 | + type: string |
| 20 | + dry_run: |
| 21 | + description: "Dry run (do not actually publish)" |
| 22 | + required: false |
| 23 | + type: boolean |
| 24 | + default: false |
| 25 | + tag: |
| 26 | + description: "NPM dist-tag" |
| 27 | + required: false |
| 28 | + type: choice |
| 29 | + options: |
| 30 | + - latest |
| 31 | + - next |
| 32 | + - beta |
| 33 | + - alpha |
| 34 | + default: latest |
| 35 | + |
| 36 | +concurrency: |
| 37 | + group: publish-npm |
| 38 | + cancel-in-progress: false |
| 39 | + |
| 40 | +permissions: |
| 41 | + contents: write |
| 42 | + id-token: write |
| 43 | + |
| 44 | +jobs: |
| 45 | + publish-sdk: |
| 46 | + name: Publish @relayfile/sdk |
| 47 | + runs-on: ubuntu-latest |
| 48 | + |
| 49 | + steps: |
| 50 | + - name: Checkout |
| 51 | + uses: actions/checkout@v4 |
| 52 | + with: |
| 53 | + fetch-depth: 0 |
| 54 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + - name: Setup Node 22 |
| 57 | + uses: actions/setup-node@v4 |
| 58 | + with: |
| 59 | + node-version: "22" |
| 60 | + cache: npm |
| 61 | + cache-dependency-path: packages/relayfile-sdk/package-lock.json |
| 62 | + registry-url: "https://registry.npmjs.org" |
| 63 | + |
| 64 | + - name: Update npm to latest |
| 65 | + run: npm install -g npm@latest |
| 66 | + |
| 67 | + - name: Install deps |
| 68 | + working-directory: packages/relayfile-sdk |
| 69 | + run: npm ci |
| 70 | + |
| 71 | + - name: Version bump |
| 72 | + id: version |
| 73 | + working-directory: packages/relayfile-sdk |
| 74 | + run: | |
| 75 | + CUSTOM_VERSION="${{ github.event.inputs.custom_version }}" |
| 76 | + VERSION_TYPE="${{ github.event.inputs.version }}" |
| 77 | +
|
| 78 | + if [ -n "$CUSTOM_VERSION" ]; then |
| 79 | + npm version "$CUSTOM_VERSION" --no-git-tag-version --allow-same-version |
| 80 | + else |
| 81 | + npm version "$VERSION_TYPE" --no-git-tag-version |
| 82 | + fi |
| 83 | +
|
| 84 | + NEW_VERSION="$(node -p "require('./package.json').version")" |
| 85 | + echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 86 | + echo "tag_name=sdk-v$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 87 | +
|
| 88 | + - name: Build |
| 89 | + working-directory: packages/relayfile-sdk |
| 90 | + run: npm run build |
| 91 | + |
| 92 | + - name: Test |
| 93 | + working-directory: packages/relayfile-sdk |
| 94 | + run: npx tsc --noEmit |
| 95 | + |
| 96 | + - name: Dry run check |
| 97 | + if: github.event.inputs.dry_run == 'true' |
| 98 | + working-directory: packages/relayfile-sdk |
| 99 | + run: npm publish --dry-run --access public --tag "${{ github.event.inputs.tag }}" --ignore-scripts |
| 100 | + |
| 101 | + - name: Publish |
| 102 | + if: github.event.inputs.dry_run != 'true' |
| 103 | + working-directory: packages/relayfile-sdk |
| 104 | + run: npm publish --access public --provenance --tag "${{ github.event.inputs.tag }}" --ignore-scripts |
| 105 | + |
| 106 | + - name: Commit version bump and create git tag |
| 107 | + if: github.event.inputs.dry_run != 'true' |
| 108 | + run: | |
| 109 | + NEW_VERSION="${{ steps.version.outputs.new_version }}" |
| 110 | + TAG_NAME="${{ steps.version.outputs.tag_name }}" |
| 111 | +
|
| 112 | + git config user.name "GitHub Actions" |
| 113 | + git config user.email "actions@github.com" |
| 114 | +
|
| 115 | + git add packages/relayfile-sdk/package.json packages/relayfile-sdk/package-lock.json |
| 116 | + git commit -m "chore(sdk): release v${NEW_VERSION}" |
| 117 | + git tag -a "${TAG_NAME}" -m "SDK ${NEW_VERSION}" |
| 118 | +
|
| 119 | + git push origin HEAD:main |
| 120 | + git push origin "${TAG_NAME}" |
| 121 | +
|
| 122 | + - name: Create GitHub Release |
| 123 | + if: github.event.inputs.dry_run != 'true' |
| 124 | + uses: softprops/action-gh-release@v2 |
| 125 | + with: |
| 126 | + tag_name: ${{ steps.version.outputs.tag_name }} |
| 127 | + name: ${{ steps.version.outputs.tag_name }} |
| 128 | + body: | |
| 129 | + ## @relayfile/sdk ${{ steps.version.outputs.new_version }} |
| 130 | +
|
| 131 | + Install: |
| 132 | + ```bash |
| 133 | + npm install @relayfile/sdk@${{ steps.version.outputs.new_version }} |
| 134 | + ``` |
| 135 | +
|
| 136 | + Dist-tag: `${{ github.event.inputs.tag }}` |
| 137 | + Provenance: enabled via `npm publish --provenance` |
| 138 | + generate_release_notes: true |
| 139 | + env: |
| 140 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 141 | + |
| 142 | + publish-cli: |
| 143 | + name: Publish relayfile (CLI) |
| 144 | + runs-on: ubuntu-latest |
| 145 | + needs: publish-sdk |
| 146 | + |
| 147 | + steps: |
| 148 | + - name: Checkout |
| 149 | + uses: actions/checkout@v4 |
| 150 | + |
| 151 | + - name: Setup Node 22 |
| 152 | + uses: actions/setup-node@v4 |
| 153 | + with: |
| 154 | + node-version: "22" |
| 155 | + registry-url: "https://registry.npmjs.org" |
| 156 | + |
| 157 | + - name: Update npm to latest |
| 158 | + run: npm install -g npm@latest |
| 159 | + |
| 160 | + - name: Sync version with SDK |
| 161 | + working-directory: packages/relayfile |
| 162 | + run: | |
| 163 | + SDK_VERSION="$(node -p "require('../relayfile-sdk/package.json').version")" |
| 164 | + npm version "$SDK_VERSION" --no-git-tag-version --allow-same-version |
| 165 | +
|
| 166 | + - name: Dry run check |
| 167 | + if: github.event.inputs.dry_run == 'true' |
| 168 | + working-directory: packages/relayfile |
| 169 | + run: npm publish --dry-run --access public --tag "${{ github.event.inputs.tag }}" |
| 170 | + |
| 171 | + - name: Publish |
| 172 | + if: github.event.inputs.dry_run != 'true' |
| 173 | + working-directory: packages/relayfile |
| 174 | + run: npm publish --access public --provenance --tag "${{ github.event.inputs.tag }}" |
0 commit comments