Build-n-Release #30
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build-n-Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| ref_name: | |
| description: Release Version | |
| required: true | |
| release: | |
| description: Upload release assets | |
| required: true | |
| type: boolean | |
| default: true | |
| release: | |
| types: [published] | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| goos: [linux] | |
| goarch: [amd64, arm64] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref_name || github.ref }} | |
| - name: Use isolated Go cache paths | |
| run: | | |
| GO_MOD_CACHE=$(mktemp -d "${RUNNER_TEMP}/gomodcache.XXXXXX") | |
| GO_BUILD_CACHE=$(mktemp -d "${RUNNER_TEMP}/gocache.XXXXXX") | |
| echo "GOMODCACHE=$GO_MOD_CACHE" >> "$GITHUB_ENV" | |
| echo "GOCACHE=$GO_BUILD_CACHE" >> "$GITHUB_ENV" | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: "1.26.1" | |
| cache: false | |
| - name: Set version | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| VERSION="${{ inputs.ref_name }}" | |
| else | |
| VERSION="${{ github.ref_name }}" | |
| fi | |
| VERSION="${VERSION#v}" | |
| if [ -z "${VERSION}" ]; then | |
| echo "::error::VERSION is empty. Provide version via ref_name input or valid tag." | |
| exit 1 | |
| fi | |
| TMP_FILE=$(mktemp) | |
| awk -v version="$VERSION" ' | |
| $0 ~ /^[[:space:]]*Version[[:space:]]*=/ { | |
| sub(/"[^"]*"/, "\"" version "\"") | |
| } | |
| { print } | |
| ' cmd/gossip/version.go > "$TMP_FILE" | |
| mv "$TMP_FILE" cmd/gossip/version.go | |
| if ! grep -qF "\"${VERSION}\"" cmd/gossip/version.go; then | |
| echo "::error::failed to update cmd/gossip/version.go to ${VERSION}" | |
| exit 1 | |
| fi | |
| echo "VERSION=${VERSION}" >> "$GITHUB_ENV" | |
| - name: Test | |
| run: go test ./... | |
| - name: Build binary | |
| env: | |
| VERSION: ${{ env.VERSION }} | |
| OS: ${{ matrix.goos }} | |
| ARCH: ${{ matrix.goarch }} | |
| run: | | |
| make build VERSION="${VERSION}" OS="${OS}" ARCH="${ARCH}" | |
| mv "dist/gossipper" "dist/gossipper_${OS}_${ARCH}" | |
| - name: Install nfpm | |
| if: github.event_name == 'release' || inputs.release | |
| run: | | |
| wget -qO- https://github.com/goreleaser/nfpm/releases/download/v2.41.1/nfpm_2.41.1_Linux_x86_64.tar.gz | tar --directory ./ -xz nfpm | |
| chmod +x nfpm | |
| echo "$PWD" >> "$GITHUB_PATH" | |
| - name: Create packages | |
| if: github.event_name == 'release' || inputs.release | |
| env: | |
| VERSION: ${{ env.VERSION }} | |
| OS: ${{ matrix.goos }} | |
| ARCH: ${{ matrix.goarch }} | |
| run: | | |
| scripts/build-package.sh deb | |
| scripts/build-package.sh rpm | |
| - name: Upload workflow artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: gossipper-${{ matrix.goos }}-${{ matrix.goarch }} | |
| path: | | |
| dist/gossipper_${{ matrix.goos }}_${{ matrix.goarch }} | |
| dist/gossipper_${{ env.VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.deb | |
| dist/gossipper_${{ env.VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.rpm | |
| if-no-files-found: ignore | |
| - name: Upload release assets | |
| if: github.event_name == 'release' || inputs.release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ env.VERSION }} | |
| files: | | |
| dist/gossipper_${{ matrix.goos }}_${{ matrix.goarch }} | |
| dist/gossipper_${{ env.VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.deb | |
| dist/gossipper_${{ env.VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.rpm | |
| fail_on_unmatched_files: true |