|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + releases: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + name: Build ${{ matrix.target }} |
| 17 | + runs-on: ${{ matrix.runner }} |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + include: |
| 22 | + - target: linux-x64 |
| 23 | + runner: ubuntu-latest |
| 24 | + artifact: spm-linux-x64 |
| 25 | + - target: darwin-arm64 |
| 26 | + runner: macos-latest |
| 27 | + artifact: spm-darwin-arm64 |
| 28 | + - target: darwin-x64 |
| 29 | + runner: macos-latest |
| 30 | + artifact: spm-darwin-x64 |
| 31 | + - target: windows-x64 |
| 32 | + runner: windows-latest |
| 33 | + artifact: spm-windows-x64.exe |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Setup Bun |
| 40 | + uses: oven-sh/setup-bun@v2 |
| 41 | + |
| 42 | + - name: Install dependencies |
| 43 | + run: bun install --frozen-lockfile |
| 44 | + |
| 45 | + - name: Build binary |
| 46 | + run: | |
| 47 | + case "${{ matrix.target }}" in |
| 48 | + linux-x64) |
| 49 | + bun build index.ts --compile --target=bun-linux-x64 --outfile dist/spm-linux-x64 |
| 50 | + ;; |
| 51 | + darwin-arm64) |
| 52 | + bun build index.ts --compile --target=bun-darwin-arm64 --outfile dist/spm-darwin-arm64 |
| 53 | + ;; |
| 54 | + darwin-x64) |
| 55 | + bun build index.ts --compile --target=bun-darwin-x64 --outfile dist/spm-darwin-x64 |
| 56 | + ;; |
| 57 | + windows-x64) |
| 58 | + bun build index.ts --compile --target=bun-windows-x64 --outfile dist/spm-windows-x64.exe |
| 59 | + ;; |
| 60 | + esac |
| 61 | +
|
| 62 | + - name: Upload artifact |
| 63 | + uses: actions/upload-artifact@v4 |
| 64 | + with: |
| 65 | + name: spm-${{ matrix.target }} |
| 66 | + path: dist/${{ matrix.artifact }} |
| 67 | + |
| 68 | + release: |
| 69 | + name: Create Release |
| 70 | + runs-on: ubuntu-latest |
| 71 | + needs: build |
| 72 | + if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') |
| 73 | + |
| 74 | + steps: |
| 75 | + - name: Checkout |
| 76 | + uses: actions/checkout@v4 |
| 77 | + |
| 78 | + - name: Download all artifacts |
| 79 | + uses: actions/download-artifact@v4 |
| 80 | + with: |
| 81 | + path: artifacts |
| 82 | + |
| 83 | + - name: Prepare release assets |
| 84 | + run: | |
| 85 | + mkdir -p release |
| 86 | + for dir in artifacts/spm-*/; do |
| 87 | + cp "$dir"/* release/ 2>/dev/null || true |
| 88 | + done |
| 89 | + ls -la release/ |
| 90 | +
|
| 91 | + - name: Determine version |
| 92 | + id: version |
| 93 | + run: | |
| 94 | + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then |
| 95 | + echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 96 | + echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 97 | + echo "prerelease=false" >> $GITHUB_OUTPUT |
| 98 | + else |
| 99 | + VERSION=$(node -p "require('./package.json').version") |
| 100 | + SHORT_SHA=$(git rev-parse --short HEAD) |
| 101 | + echo "version=${VERSION}-main.${SHORT_SHA}" >> $GITHUB_OUTPUT |
| 102 | + echo "tag=v${VERSION}-main.${SHORT_SHA}" >> $GITHUB_OUTPUT |
| 103 | + echo "prerelease=true" >> $GITHUB_OUTPUT |
| 104 | + fi |
| 105 | +
|
| 106 | + - name: Create Release |
| 107 | + uses: softprops/action-gh-release@v2 |
| 108 | + with: |
| 109 | + tag_name: ${{ steps.version.outputs.tag }} |
| 110 | + name: ${{ steps.version.outputs.tag }} |
| 111 | + prerelease: ${{ steps.version.outputs.prerelease }} |
| 112 | + generate_release_notes: true |
| 113 | + files: release/* |
| 114 | + env: |
| 115 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments