|
| 1 | +name: Release and Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + packages: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + version-bump: |
| 14 | + name: Bump Version |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + new_version: ${{ steps.bump.outputs.new_version }} |
| 18 | + new_tag: ${{ steps.bump.outputs.new_tag }} |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + |
| 26 | + - name: Setup Node.js |
| 27 | + uses: actions/setup-node@v4 |
| 28 | + with: |
| 29 | + node-version: '18' |
| 30 | + |
| 31 | + - name: Configure Git |
| 32 | + run: | |
| 33 | + git config user.name "github-actions[bot]" |
| 34 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 35 | +
|
| 36 | + - name: Bump version |
| 37 | + id: bump |
| 38 | + run: | |
| 39 | + cd cli |
| 40 | + npm version patch --no-git-tag-version |
| 41 | + NEW_VERSION=$(node -p "require('./package.json').version") |
| 42 | + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 43 | + echo "new_tag=v$NEW_VERSION" >> $GITHUB_OUTPUT |
| 44 | + cd .. |
| 45 | +
|
| 46 | + # Update root package.json version to match |
| 47 | + npm version $NEW_VERSION --no-git-tag-version --allow-same-version |
| 48 | +
|
| 49 | + git add cli/package.json package.json package-lock.json cli/package-lock.json |
| 50 | + git commit -m "chore: bump version to $NEW_VERSION" |
| 51 | + git tag "v$NEW_VERSION" |
| 52 | + git push origin main |
| 53 | + git push origin "v$NEW_VERSION" |
| 54 | +
|
| 55 | + build-binaries: |
| 56 | + name: Build Binary (${{ matrix.os }}) |
| 57 | + needs: version-bump |
| 58 | + runs-on: ${{ matrix.os }} |
| 59 | + strategy: |
| 60 | + matrix: |
| 61 | + include: |
| 62 | + - os: ubuntu-latest |
| 63 | + platform: linux |
| 64 | + arch: x64 |
| 65 | + - os: macos-latest |
| 66 | + platform: macos |
| 67 | + arch: arm64 |
| 68 | + - os: windows-latest |
| 69 | + platform: windows |
| 70 | + arch: x64 |
| 71 | + steps: |
| 72 | + - name: Checkout code |
| 73 | + uses: actions/checkout@v4 |
| 74 | + with: |
| 75 | + ref: ${{ needs.version-bump.outputs.new_tag }} |
| 76 | + |
| 77 | + - name: Setup Node.js |
| 78 | + uses: actions/setup-node@v4 |
| 79 | + with: |
| 80 | + node-version: '18' |
| 81 | + |
| 82 | + - name: Setup Bun |
| 83 | + uses: oven-sh/setup-bun@v2 |
| 84 | + with: |
| 85 | + bun-version: latest |
| 86 | + |
| 87 | + - name: Install dependencies |
| 88 | + run: | |
| 89 | + npm install |
| 90 | + cd cli |
| 91 | + npm install |
| 92 | +
|
| 93 | + - name: Build CLI binary |
| 94 | + run: npm run build:cli |
| 95 | + |
| 96 | + - name: Rename binary (Unix) |
| 97 | + if: matrix.platform != 'windows' |
| 98 | + run: | |
| 99 | + mv dist/facet dist/facet-${{ matrix.platform }} |
| 100 | +
|
| 101 | + - name: Rename binary (Windows) |
| 102 | + if: matrix.platform == 'windows' |
| 103 | + run: | |
| 104 | + mv dist/facet dist/facet-${{ matrix.platform }}.exe |
| 105 | +
|
| 106 | + - name: Upload binary artifact |
| 107 | + uses: actions/upload-artifact@v4 |
| 108 | + with: |
| 109 | + name: facet-${{ matrix.platform }}-${{ matrix.arch }} |
| 110 | + path: | |
| 111 | + dist/facet-${{ matrix.platform }}* |
| 112 | + retention-days: 1 |
| 113 | + |
| 114 | + create-release: |
| 115 | + name: Create GitHub Release |
| 116 | + needs: [version-bump, build-binaries] |
| 117 | + runs-on: ubuntu-latest |
| 118 | + steps: |
| 119 | + - name: Download all artifacts |
| 120 | + uses: actions/download-artifact@v4 |
| 121 | + with: |
| 122 | + path: binaries |
| 123 | + |
| 124 | + - name: Display structure of downloaded files |
| 125 | + run: ls -R binaries |
| 126 | + |
| 127 | + - name: Create Release |
| 128 | + env: |
| 129 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 130 | + run: | |
| 131 | + gh release create ${{ needs.version-bump.outputs.new_tag }} \ |
| 132 | + --repo ${{ github.repository }} \ |
| 133 | + --title "Release ${{ needs.version-bump.outputs.new_tag }}" \ |
| 134 | + --notes "Release ${{ needs.version-bump.outputs.new_version }}" \ |
| 135 | + binaries/facet-linux-x64/facet-linux \ |
| 136 | + binaries/facet-macos-arm64/facet-macos \ |
| 137 | + binaries/facet-windows-x64/facet-windows.exe |
| 138 | +
|
| 139 | + publish-npm: |
| 140 | + name: Publish to npm |
| 141 | + needs: [version-bump, build-binaries] |
| 142 | + runs-on: ubuntu-latest |
| 143 | + steps: |
| 144 | + - name: Checkout code |
| 145 | + uses: actions/checkout@v4 |
| 146 | + with: |
| 147 | + ref: ${{ needs.version-bump.outputs.new_tag }} |
| 148 | + |
| 149 | + - name: Setup Node.js |
| 150 | + uses: actions/setup-node@v4 |
| 151 | + with: |
| 152 | + node-version: '18' |
| 153 | + registry-url: 'https://registry.npmjs.org' |
| 154 | + |
| 155 | + - name: Install dependencies |
| 156 | + run: | |
| 157 | + npm install |
| 158 | + cd cli |
| 159 | + npm install |
| 160 | +
|
| 161 | + - name: Build CLI |
| 162 | + run: npm run build:cli |
| 163 | + |
| 164 | + - name: Publish to npm |
| 165 | + env: |
| 166 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 167 | + run: npm publish --access public |
0 commit comments