|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: [ 'v*' ] # v0.1.0 などのタグで実行 |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + tag: |
| 9 | + description: 'Release tag (e.g., v1.0.0)' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +env: |
| 14 | + APP_NAME: ghosttype |
| 15 | + GO_VERSION: '1.24' |
| 16 | + RELEASE_TAG: ${{ github.ref_name != '' && github.ref_name || inputs.tag }} |
| 17 | + |
| 18 | +jobs: |
| 19 | + # ─────────────────────────────── |
| 20 | + # Linux (amd64 / arm64) |
| 21 | + # ─────────────────────────────── |
| 22 | + build-linux: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + include: |
| 29 | + - goarch: amd64 |
| 30 | + cc: gcc |
| 31 | + install_cross: '' |
| 32 | + - goarch: arm64 |
| 33 | + cc: aarch64-linux-gnu-gcc |
| 34 | + install_cross: gcc-aarch64-linux-gnu |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + |
| 42 | + - name: Install cross-compiler |
| 43 | + if: ${{ matrix.install_cross != '' }} |
| 44 | + run: | |
| 45 | + sudo apt-get update |
| 46 | + sudo apt-get install -y ${{ matrix.install_cross }} |
| 47 | +
|
| 48 | + - name: Set up Go |
| 49 | + uses: actions/setup-go@v4 |
| 50 | + with: |
| 51 | + go-version: ${{ env.GO_VERSION }} |
| 52 | + |
| 53 | + - name: Build linux/${{ matrix.goarch }} |
| 54 | + env: |
| 55 | + GOOS: linux |
| 56 | + GOARCH: ${{ matrix.goarch }} |
| 57 | + CGO_ENABLED: '1' |
| 58 | + CC: ${{ matrix.cc }} |
| 59 | + run: | |
| 60 | + mkdir -p bin |
| 61 | + go build -tags=libsql -o bin/${{ env.APP_NAME }} ./main.go |
| 62 | +
|
| 63 | + - name: Package |
| 64 | + run: | |
| 65 | + mkdir -p dist |
| 66 | + tar -C bin -czf dist/${{ env.APP_NAME }}_${{ github.ref_name }}_linux_${{ matrix.goarch }}.tar.gz ${{ env.APP_NAME }} |
| 67 | +
|
| 68 | + - name: Upload artifact |
| 69 | + uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: linux-${{ matrix.goarch }} |
| 72 | + path: dist/*.tar.gz |
| 73 | + |
| 74 | + # ─────────────────────────────── |
| 75 | + # macOS (amd64 / arm64) |
| 76 | + # ─────────────────────────────── |
| 77 | + build-macos: |
| 78 | + runs-on: macos-latest |
| 79 | + |
| 80 | + strategy: |
| 81 | + fail-fast: false |
| 82 | + matrix: |
| 83 | + goarch: [ arm64 ] |
| 84 | + |
| 85 | + steps: |
| 86 | + - name: Checkout |
| 87 | + uses: actions/checkout@v4 |
| 88 | + with: |
| 89 | + fetch-depth: 0 |
| 90 | + |
| 91 | + - name: Set up Go |
| 92 | + uses: actions/setup-go@v4 |
| 93 | + with: |
| 94 | + go-version: ${{ env.GO_VERSION }} |
| 95 | + |
| 96 | + - name: Build darwin/${{ matrix.goarch }} |
| 97 | + env: |
| 98 | + GOOS: darwin |
| 99 | + GOARCH: ${{ matrix.goarch }} |
| 100 | + CGO_ENABLED: '1' |
| 101 | + run: | |
| 102 | + mkdir -p bin |
| 103 | + go build -tags=libsql -o bin/${{ env.APP_NAME }} ./main.go |
| 104 | +
|
| 105 | + - name: Package |
| 106 | + run: | |
| 107 | + mkdir -p dist |
| 108 | + tar -C bin -czf dist/${{ env.APP_NAME }}_${{ github.ref_name }}_darwin_${{ matrix.goarch }}.tar.gz ${{ env.APP_NAME }} |
| 109 | +
|
| 110 | + - name: Upload artifact |
| 111 | + uses: actions/upload-artifact@v4 |
| 112 | + with: |
| 113 | + name: darwin-${{ matrix.goarch }} |
| 114 | + path: dist/*.tar.gz |
| 115 | + # ─────────────────────────────── |
| 116 | + # Release job (collect & publish) |
| 117 | + # ─────────────────────────────── |
| 118 | + release: |
| 119 | + needs: |
| 120 | + - build-linux |
| 121 | + - build-macos |
| 122 | + runs-on: ubuntu-latest |
| 123 | + steps: |
| 124 | + - name: Download all artifacts |
| 125 | + uses: actions/download-artifact@v4 |
| 126 | + with: |
| 127 | + path: dist |
| 128 | + |
| 129 | + - name: Create GitHub Release |
| 130 | + uses: softprops/action-gh-release@v1 |
| 131 | + with: |
| 132 | + tag_name: ${{ env.RELEASE_TAG }} |
| 133 | + files: dist/**/*.tar.gz |
| 134 | + draft: false # 必要なら true |
| 135 | + prerelease: false |
| 136 | + env: |
| 137 | + GITHUB_TOKEN: ${{ secrets.GH_PAT }} |
0 commit comments