Merge pull request #131 from hdresearch/ty/fix-login #68
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 and Release Go Binary | |
| on: | |
| push: | |
| branches: ["main"] | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| env: | |
| GO_VERSION: "1.24" | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| build: | |
| name: Build (${{ matrix.os }}-${{ matrix.arch }}) | |
| runs-on: ${{ matrix.os }} | |
| permissions: | |
| contents: write | |
| packages: write | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| goos: linux | |
| arch: amd64 | |
| artifact_name: vers-linux-amd64 | |
| asset_name: vers-linux-amd64 | |
| - os: ubuntu-latest | |
| goos: linux | |
| arch: arm64 | |
| artifact_name: vers-linux-arm64 | |
| asset_name: vers-linux-arm64 | |
| - os: ubuntu-latest | |
| goos: darwin | |
| arch: amd64 | |
| artifact_name: vers-darwin-amd64 | |
| asset_name: vers-darwin-amd64 | |
| - os: ubuntu-latest | |
| goos: darwin | |
| arch: arm64 | |
| artifact_name: vers-darwin-arm64 | |
| asset_name: vers-darwin-arm64 | |
| - os: ubuntu-latest | |
| goos: windows | |
| arch: amd64 | |
| artifact_name: vers-windows-amd64.exe | |
| asset_name: vers-windows-amd64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Cache Go modules | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-v1 | |
| restore-keys: | | |
| ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}- | |
| ${{ runner.os }}-go- | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Get build info | |
| id: build_info | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
| VERSION="${{ github.ref_name }}" | |
| elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
| VERSION="nightly-$(git rev-parse --short HEAD)" | |
| else | |
| VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev-$(git rev-parse --short HEAD)") | |
| fi | |
| GIT_COMMIT=$(git rev-parse HEAD) | |
| BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "git_commit=$GIT_COMMIT" >> $GITHUB_OUTPUT | |
| echo "build_date=$BUILD_DATE" >> $GITHUB_OUTPUT | |
| echo "Building version: $VERSION" | |
| echo "Git commit: $GIT_COMMIT" | |
| echo "Build date: $BUILD_DATE" | |
| - name: Build Release Binary | |
| run: | | |
| LDFLAGS="-s -w \ | |
| -X 'github.com/hdresearch/vers-cli/cmd.Version=${{ steps.build_info.outputs.version }}' \ | |
| -X 'github.com/hdresearch/vers-cli/cmd.GitCommit=${{ steps.build_info.outputs.git_commit }}' \ | |
| -X 'github.com/hdresearch/vers-cli/cmd.BuildDate=${{ steps.build_info.outputs.build_date }}' \ | |
| -X 'github.com/hdresearch/vers-cli/cmd.Name=vers-cli' \ | |
| -X 'github.com/hdresearch/vers-cli/cmd.Description=A CLI tool for version management' \ | |
| -X 'github.com/hdresearch/vers-cli/cmd.Author=the VERS team' \ | |
| -X 'github.com/hdresearch/vers-cli/cmd.Repository=https://github.com/hdresearch/vers-cli' \ | |
| -X 'github.com/hdresearch/vers-cli/cmd.License=MIT'" | |
| GOOS=${{ matrix.goos }} GOARCH=${{ matrix.arch }} \ | |
| go build -ldflags "$LDFLAGS" -o ${{ matrix.artifact_name }} ./cmd/vers | |
| - name: Generate checksums | |
| shell: bash | |
| run: | | |
| # Generate SHA256 checksum | |
| sha256sum ${{ matrix.artifact_name }} > ${{ matrix.artifact_name }}.sha256 | |
| # Also create a JSON metadata file with size and checksum info | |
| SIZE=$(stat -c%s ${{ matrix.artifact_name }} 2>/dev/null || stat -f%z ${{ matrix.artifact_name }}) | |
| SHA256=$(cut -d' ' -f1 ${{ matrix.artifact_name }}.sha256) | |
| echo "{\"filename\":\"${{ matrix.artifact_name }}\",\"size\":$SIZE,\"sha256\":\"$SHA256\",\"version\":\"${{ steps.build_info.outputs.version }}\",\"goos\":\"${{ matrix.goos }}\",\"goarch\":\"${{ matrix.arch }}\"}" > ${{ matrix.artifact_name }}.json | |
| cat ${{ matrix.artifact_name }}.sha256 | |
| cat ${{ matrix.artifact_name }}.json | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.asset_name }} | |
| path: | | |
| ${{ matrix.artifact_name }} | |
| ${{ matrix.artifact_name }}.sha256 | |
| ${{ matrix.artifact_name }}.json | |
| if-no-files-found: error | |
| release: | |
| name: Create Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Generate release info | |
| id: release_info | |
| run: | | |
| if [ "${{ github.ref }}" = "refs/heads/main" ]; then | |
| echo "name=nightly" >> $GITHUB_OUTPUT | |
| echo "tag=nightly" >> $GITHUB_OUTPUT | |
| echo "is_prerelease=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "name=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
| echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
| echo "is_prerelease=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Download release artifacts | |
| uses: actions/download-artifact@v4 | |
| - name: Delete existing nightly release and tag | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| gh release delete nightly --yes || true | |
| git push origin :refs/tags/nightly || true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| name: ${{ steps.release_info.outputs.name }} | |
| tag_name: ${{ steps.release_info.outputs.tag }} | |
| files: | | |
| vers-linux-amd64/vers-linux-amd64 | |
| vers-linux-amd64/vers-linux-amd64.sha256 | |
| vers-linux-amd64/vers-linux-amd64.json | |
| vers-linux-arm64/vers-linux-arm64 | |
| vers-linux-arm64/vers-linux-arm64.sha256 | |
| vers-linux-arm64/vers-linux-arm64.json | |
| vers-darwin-amd64/vers-darwin-amd64 | |
| vers-darwin-amd64/vers-darwin-amd64.sha256 | |
| vers-darwin-amd64/vers-darwin-amd64.json | |
| vers-darwin-arm64/vers-darwin-arm64 | |
| vers-darwin-arm64/vers-darwin-arm64.sha256 | |
| vers-darwin-arm64/vers-darwin-arm64.json | |
| vers-windows-amd64/vers-windows-amd64.exe | |
| vers-windows-amd64/vers-windows-amd64.exe.sha256 | |
| vers-windows-amd64/vers-windows-amd64.exe.json | |
| draft: false | |
| prerelease: ${{ steps.release_info.outputs.is_prerelease }} | |
| body: | | |
| ${{ github.ref == 'refs/heads/main' && format('Nightly build from commit {0}', github.sha) || '' }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| test: | |
| name: Test Binary | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download Linux binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: vers-linux-amd64 | |
| path: ./ | |
| - name: Test binary | |
| run: | | |
| chmod +x ./vers-linux-amd64 | |
| echo "Testing version command:" | |
| ./vers-linux-amd64 --version | |
| echo -e "\nTesting metadata command:" | |
| ./vers-linux-amd64 --VVersion || echo "Metadata command test completed" | |
| # homebrew: | |
| # name: Update Homebrew Tap | |
| # needs: release | |
| # runs-on: ubuntu-latest | |
| # if: startsWith(github.ref, 'refs/tags/') | |
| # steps: | |
| # - name: Update Homebrew tap | |
| # uses: mislav/bump-homebrew-formula-action@v3 | |
| # with: | |
| # formula-name: vers-cli | |
| # formula-path: Formula/vers-cli.rb | |
| # homebrew-tap: hdresearch/homebrew-vers-cli | |
| # base-branch: main | |
| # download-url: https://github.com/hdresearch/vers-cli/releases/download/${{ github.ref_name }}/vers-darwin-amd64 | |
| # commit-message: | | |
| # vers-cli ${{ github.ref_name }} | |
| # Created by bump-homebrew-formula-action | |
| # env: | |
| # COMMITTER_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} |