name: Release on: push: tags: - 'v*' permissions: contents: write jobs: build: name: Build ${{ matrix.os }}-${{ matrix.arch }} runs-on: ubuntu-latest strategy: matrix: include: - os: linux arch: amd64 - os: linux arch: arm64 - os: darwin arch: amd64 - os: darwin arch: arm64 steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v5 with: go-version: '1.21' - name: Get version id: version run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT - name: Build binary env: GOOS: ${{ matrix.os }} GOARCH: ${{ matrix.arch }} CGO_ENABLED: 0 run: | mkdir -p dist BINARY_NAME=go-alived-${{ matrix.os }}-${{ matrix.arch }} if [ "${{ matrix.os }}" = "windows" ]; then BINARY_NAME="${BINARY_NAME}.exe" fi go build -ldflags="-s -w -X github.com/loveuer/go-alived/internal/cmd.Version=${{ steps.version.outputs.VERSION }}" \ -o dist/${BINARY_NAME} . # Create checksum cd dist && sha256sum ${BINARY_NAME} > ${BINARY_NAME}.sha256 - name: Upload artifact uses: actions/upload-artifact@v4 with: name: go-alived-${{ matrix.os }}-${{ matrix.arch }} path: dist/ release: name: Create Release needs: build runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Download all artifacts uses: actions/download-artifact@v4 with: path: artifacts - name: Prepare release files run: | mkdir -p release find artifacts -type f -exec cp {} release/ \; ls -la release/ - name: Get version id: version run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT - name: Create Release uses: softprops/action-gh-release@v1 with: name: Release ${{ steps.version.outputs.VERSION }} draft: false prerelease: ${{ contains(github.ref, '-rc') || contains(github.ref, '-beta') || contains(github.ref, '-alpha') }} generate_release_notes: true files: release/* env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}