|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + REGISTRY: ghcr.io |
| 11 | + IMAGE_NAME: ${{ github.repository }} |
| 12 | + |
| 13 | +jobs: |
| 14 | + create-release: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 18 | + version: ${{ steps.get_version.outputs.version }} |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Get version |
| 24 | + id: get_version |
| 25 | + run: | |
| 26 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 27 | + VERSION=${GITHUB_REF#refs/tags/} |
| 28 | + else |
| 29 | + VERSION=$(git describe --tags --always) |
| 30 | + fi |
| 31 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 32 | + echo "Version: ${VERSION}" |
| 33 | +
|
| 34 | + - name: Extract release notes |
| 35 | + id: extract_notes |
| 36 | + run: | |
| 37 | + # Extract version-specific notes from CHANGELOG.md if it exists |
| 38 | + if [ -f CHANGELOG.md ]; then |
| 39 | + VERSION=${{ steps.get_version.outputs.version }} |
| 40 | + # Simple extraction - customize as needed |
| 41 | + echo "notes<<EOF" >> $GITHUB_OUTPUT |
| 42 | + echo "Release ${VERSION}" >> $GITHUB_OUTPUT |
| 43 | + echo "" >> $GITHUB_OUTPUT |
| 44 | + echo "Built with Neutrino v0.16.0" >> $GITHUB_OUTPUT |
| 45 | + echo "EOF" >> $GITHUB_OUTPUT |
| 46 | + else |
| 47 | + echo "notes=Release ${{ steps.get_version.outputs.version }}" >> $GITHUB_OUTPUT |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Create Release |
| 51 | + id: create_release |
| 52 | + uses: actions/create-release@v1 |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + with: |
| 56 | + tag_name: ${{ github.ref }} |
| 57 | + release_name: Release ${{ steps.get_version.outputs.version }} |
| 58 | + body: ${{ steps.extract_notes.outputs.notes }} |
| 59 | + draft: false |
| 60 | + prerelease: false |
| 61 | + |
| 62 | + build-binaries: |
| 63 | + needs: create-release |
| 64 | + runs-on: ubuntu-latest |
| 65 | + strategy: |
| 66 | + matrix: |
| 67 | + include: |
| 68 | + - goos: linux |
| 69 | + goarch: amd64 |
| 70 | + output: neutrinod-linux-amd64 |
| 71 | + - goos: linux |
| 72 | + goarch: arm64 |
| 73 | + output: neutrinod-linux-arm64 |
| 74 | + - goos: darwin |
| 75 | + goarch: amd64 |
| 76 | + output: neutrinod-darwin-amd64 |
| 77 | + - goos: darwin |
| 78 | + goarch: arm64 |
| 79 | + output: neutrinod-darwin-arm64 |
| 80 | + - goos: windows |
| 81 | + goarch: amd64 |
| 82 | + output: neutrinod-windows-amd64.exe |
| 83 | + |
| 84 | + steps: |
| 85 | + - name: Checkout |
| 86 | + uses: actions/checkout@v4 |
| 87 | + |
| 88 | + - name: Set up Go |
| 89 | + uses: actions/setup-go@v5 |
| 90 | + with: |
| 91 | + go-version: '1.21' |
| 92 | + cache-dependency-path: neutrino_server/go.sum |
| 93 | + |
| 94 | + - name: Get dependencies |
| 95 | + working-directory: neutrino_server |
| 96 | + run: go mod download |
| 97 | + |
| 98 | + - name: Build binary |
| 99 | + working-directory: neutrino_server |
| 100 | + env: |
| 101 | + GOOS: ${{ matrix.goos }} |
| 102 | + GOARCH: ${{ matrix.goarch }} |
| 103 | + CGO_ENABLED: 0 |
| 104 | + run: | |
| 105 | + VERSION=${{ needs.create-release.outputs.version }} |
| 106 | + BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S') |
| 107 | + COMMIT_HASH=$(git rev-parse --short HEAD) |
| 108 | +
|
| 109 | + go build \ |
| 110 | + -ldflags="-s -w -X main.version=${VERSION} -X main.buildTime=${BUILD_TIME} -X main.commit=${COMMIT_HASH}" \ |
| 111 | + -o ${{ matrix.output }} \ |
| 112 | + ./cmd/neutrinod |
| 113 | +
|
| 114 | + - name: Create archive |
| 115 | + run: | |
| 116 | + if [[ "${{ matrix.goos }}" == "windows" ]]; then |
| 117 | + zip neutrino_server/${{ matrix.output }}.zip neutrino_server/${{ matrix.output }} |
| 118 | + ASSET_PATH=neutrino_server/${{ matrix.output }}.zip |
| 119 | + ASSET_NAME=${{ matrix.output }}.zip |
| 120 | + else |
| 121 | + tar -czf neutrino_server/${{ matrix.output }}.tar.gz -C neutrino_server ${{ matrix.output }} |
| 122 | + ASSET_PATH=neutrino_server/${{ matrix.output }}.tar.gz |
| 123 | + ASSET_NAME=${{ matrix.output }}.tar.gz |
| 124 | + fi |
| 125 | + echo "ASSET_PATH=${ASSET_PATH}" >> $GITHUB_ENV |
| 126 | + echo "ASSET_NAME=${ASSET_NAME}" >> $GITHUB_ENV |
| 127 | +
|
| 128 | + - name: Upload Release Asset |
| 129 | + uses: actions/upload-release-asset@v1 |
| 130 | + env: |
| 131 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 132 | + with: |
| 133 | + upload_url: ${{ needs.create-release.outputs.upload_url }} |
| 134 | + asset_path: ${{ env.ASSET_PATH }} |
| 135 | + asset_name: ${{ env.ASSET_NAME }} |
| 136 | + asset_content_type: application/octet-stream |
| 137 | + |
| 138 | + build-docker: |
| 139 | + needs: create-release |
| 140 | + runs-on: ubuntu-latest |
| 141 | + permissions: |
| 142 | + contents: read |
| 143 | + packages: write |
| 144 | + |
| 145 | + steps: |
| 146 | + - name: Checkout |
| 147 | + uses: actions/checkout@v4 |
| 148 | + |
| 149 | + - name: Set up QEMU |
| 150 | + uses: docker/setup-qemu-action@v3 |
| 151 | + |
| 152 | + - name: Set up Docker Buildx |
| 153 | + uses: docker/setup-buildx-action@v3 |
| 154 | + |
| 155 | + - name: Log in to Container registry |
| 156 | + uses: docker/login-action@v3 |
| 157 | + with: |
| 158 | + registry: ${{ env.REGISTRY }} |
| 159 | + username: ${{ github.actor }} |
| 160 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 161 | + |
| 162 | + - name: Extract metadata |
| 163 | + id: meta |
| 164 | + uses: docker/metadata-action@v5 |
| 165 | + with: |
| 166 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 167 | + tags: | |
| 168 | + type=semver,pattern={{version}} |
| 169 | + type=semver,pattern={{major}}.{{minor}} |
| 170 | + type=semver,pattern={{major}} |
| 171 | + type=raw,value=latest,enable={{is_default_branch}} |
| 172 | +
|
| 173 | + - name: Build and push Docker image |
| 174 | + uses: docker/build-push-action@v5 |
| 175 | + with: |
| 176 | + context: ./neutrino_server |
| 177 | + file: ./neutrino_server/Dockerfile |
| 178 | + platforms: linux/amd64,linux/arm64 |
| 179 | + push: true |
| 180 | + tags: ${{ steps.meta.outputs.tags }} |
| 181 | + labels: ${{ steps.meta.outputs.labels }} |
| 182 | + cache-from: type=gha |
| 183 | + cache-to: type=gha,mode=max |
| 184 | + build-args: | |
| 185 | + VERSION=${{ needs.create-release.outputs.version }} |
| 186 | + BUILD_TIME=${{ github.event.repository.updated_at }} |
| 187 | + COMMIT=${{ github.sha }} |
| 188 | +
|
| 189 | + checksums: |
| 190 | + needs: [create-release, build-binaries] |
| 191 | + runs-on: ubuntu-latest |
| 192 | + steps: |
| 193 | + - name: Download all artifacts |
| 194 | + uses: actions/download-artifact@v3 |
| 195 | + with: |
| 196 | + path: ./artifacts |
| 197 | + |
| 198 | + - name: Generate checksums |
| 199 | + run: | |
| 200 | + cd artifacts |
| 201 | + find . -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec sha256sum {} \; > SHA256SUMS |
| 202 | + cat SHA256SUMS |
| 203 | +
|
| 204 | + - name: Upload checksums |
| 205 | + uses: actions/upload-release-asset@v1 |
| 206 | + env: |
| 207 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 208 | + with: |
| 209 | + upload_url: ${{ needs.create-release.outputs.upload_url }} |
| 210 | + asset_path: ./artifacts/SHA256SUMS |
| 211 | + asset_name: SHA256SUMS |
| 212 | + asset_content_type: text/plain |
0 commit comments