|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + |
| 19 | + - name: Setup Node.js |
| 20 | + uses: actions/setup-node@v4 |
| 21 | + with: |
| 22 | + node-version: '20' |
| 23 | + registry-url: 'https://registry.npmjs.org' |
| 24 | + |
| 25 | + - name: Extract version from tag |
| 26 | + id: tag_version |
| 27 | + run: | |
| 28 | + TAG_NAME=${GITHUB_REF#refs/tags/} |
| 29 | + VERSION=${TAG_NAME#v} |
| 30 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 31 | + echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT |
| 32 | + echo "Extracted version: $VERSION from tag: $TAG_NAME" |
| 33 | +
|
| 34 | + - name: Install dependencies |
| 35 | + run: npm ci |
| 36 | + |
| 37 | + - name: Update package.json versions |
| 38 | + run: | |
| 39 | + node -e " |
| 40 | + import { updatePackage } from 'write-pkg'; |
| 41 | + import path from 'path'; |
| 42 | + import { fileURLToPath } from 'url'; |
| 43 | + |
| 44 | + const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 45 | + const workspaces = ['packages/payment', 'packages/identity', 'packages/terminal']; |
| 46 | + const version = '${{ steps.tag_version.outputs.version }}'; |
| 47 | + |
| 48 | + for (const workspace of workspaces) { |
| 49 | + const packagePath = path.resolve(__dirname, '..', workspace, 'package.json'); |
| 50 | + await updatePackage(packagePath, { version }); |
| 51 | + console.log(\`Updated \${workspace}/package.json to version \${version}\`); |
| 52 | + } |
| 53 | + " |
| 54 | +
|
| 55 | + - name: Commit changes |
| 56 | + run: | |
| 57 | + git config --local user.email "[email protected]" |
| 58 | + git config --local user.name "GitHub Action" |
| 59 | + git add packages/*/package.json |
| 60 | + git commit -m "chore: update package versions to ${{ steps.tag_version.outputs.version }}" || exit 0 |
| 61 | + git push |
| 62 | +
|
| 63 | + - name: Publish packages |
| 64 | + env: |
| 65 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 66 | + run: | |
| 67 | + VERSION="${{ steps.tag_version.outputs.version }}" |
| 68 | + IS_STABLE=$(echo "$VERSION" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' && echo "true" || echo "false") |
| 69 | + |
| 70 | + for workspace in packages/payment packages/identity packages/terminal; do |
| 71 | + echo "Publishing $workspace..." |
| 72 | + cd "$workspace" |
| 73 | + npm install |
| 74 | + npm run build |
| 75 | + |
| 76 | + if [ "$IS_STABLE" = "true" ]; then |
| 77 | + npm publish |
| 78 | + else |
| 79 | + npm publish --tag next |
| 80 | + fi |
| 81 | + |
| 82 | + cd ../.. |
| 83 | + done |
| 84 | +
|
0 commit comments