Merge pull request #111 from Azure/zerolog #448
This file contains 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: "azqr-build" | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
- release-* | |
tags: | |
- v* | |
pull_request: | |
branches: | |
- main | |
- release-* | |
permissions: read-all | |
jobs: | |
build: | |
name: Build ${{ matrix.target_os }}_${{ matrix.target_arch }} binaries | |
runs-on: ${{ matrix.os }} | |
env: | |
GOVER: 1.20.3 | |
GOLANGCILINT_VER: v1.52.2 | |
GOOS: ${{ matrix.target_os }} | |
GOARCH: ${{ matrix.target_arch }} | |
GOPROXY: https://proxy.golang.org | |
ARCHIVE_OUTDIR: dist/archives | |
PROJECT_NAME: azqr | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
target_arch: [amd64, arm, arm64] | |
include: | |
- os: ubuntu-latest | |
target_os: linux | |
filename: azqr | |
- os: windows-latest | |
target_os: windows | |
filename: azqr.exe | |
- os: macOS-latest | |
target_os: darwin | |
filename: azqr | |
exclude: | |
- os: windows-latest | |
target_arch: arm | |
- os: windows-latest | |
target_arch: arm64 | |
- os: macOS-latest | |
target_arch: arm | |
steps: | |
- name: Set up Go ${{ env.GOVER }} | |
uses: actions/setup-go@v2.1.3 | |
with: | |
go-version: ${{ env.GOVER }} | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setup .NET Core | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: 6.0.x | |
- name: Setup MinVer | |
run: | | |
dotnet tool install --global minver-cli --version 4.2.0 | |
- name: golangci-lint | |
if: matrix.target_os == 'linux' && matrix.target_arch == 'amd64' | |
uses: golangci/golangci-lint-action@v3.3.1 | |
with: | |
version: ${{ env.GOLANGCILINT_VER }} | |
args: --timeout 3m --verbose | |
- name: Run go mod tidy & check diff | |
if: matrix.target_os == 'linux' && matrix.target_arch == 'amd64' | |
run: | | |
go mod tidy | |
git diff --exit-code ./go.mod | |
git diff --exit-code ./go.sum | |
- name: Run Go vet | |
if: matrix.target_os == 'linux' && matrix.target_arch == 'amd64' | |
run: | | |
go vet ./... | |
- name: Run Tests | |
if: matrix.target_os == 'linux' && matrix.target_arch == 'amd64' | |
env: | |
COVERAGE_OPTS: "-coverprofile=coverage.txt -covermode=atomic" | |
run: | | |
go install gotest.tools/gotestsum@latest | |
CGO_ENABLED=0 gotestsum --jsonfile ./test_report_unit.json --format standard-quiet -- ./... $COVERAGE_OPTS --tags=unit | |
go test ./... | |
- name: Codecov | |
if: matrix.target_os == 'linux' && matrix.target_arch == 'amd64' | |
uses: codecov/codecov-action@v3 | |
- name: Calculate Version | |
run: | | |
echo "MINVERVERSIONOVERRIDE=$($HOME/.dotnet/tools/minver -t v. -m 0.1 -d preview)" >> $GITHUB_ENV | |
if: matrix.os != 'windows-latest' | |
- name: Calculate Version Windows | |
run: | | |
echo "MINVERVERSIONOVERRIDE=$(minver -t v. -m 0.1 -d preview)" >> $env:GITHUB_ENV | |
if: matrix.os == 'windows-latest' | |
- name: output folder variable linux & mac | |
if: matrix.target_os != 'windows' | |
run: | | |
echo AZQR_OUTPUT_FOLDER=${{ env.ARCHIVE_OUTDIR }}/${{ matrix.target_os }}/${{ matrix.target_arch }} >> $GITHUB_ENV | |
- name: output folder variable windows | |
if: matrix.target_os == 'windows' | |
run: | | |
echo AZQR_OUTPUT_FOLDER=${{ env.ARCHIVE_OUTDIR }}/${{ matrix.target_os }}/${{ matrix.target_arch }} >> $env:GITHUB_ENV | |
- name: Create output folder | |
run: | | |
mkdir -p ${{ env.AZQR_OUTPUT_FOLDER }} | |
- name: Run build and archive non windows binaries | |
if: matrix.target_os != 'windows' | |
run: | | |
GOOS=${{ matrix.target_os }} GOARCH=${{ matrix.target_arch }} go build -ldflags "-s -w -X 'github.com/Azure/azqr/cmd/azqr.version=${{ env.MINVERVERSIONOVERRIDE }}'" -o ${{ env.AZQR_OUTPUT_FOLDER }}/${{ matrix.filename }} ./cmd/main.go | |
- name: Run build and archive windows binaries | |
if: matrix.target_os == 'windows' | |
run: | | |
go build -ldflags "-s -w -X 'github.com/Azure/azqr/cmd/azqr.version=${{ env.MINVERVERSIONOVERRIDE }}'" -o ${{ env.AZQR_OUTPUT_FOLDER }}/${{ matrix.filename }} ./cmd/main.go | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.PROJECT_NAME }}-${{ matrix.os }}-${{ matrix.target_arch }} | |
path: ${{ env.AZQR_OUTPUT_FOLDER }}/${{ matrix.filename }} | |
release: | |
name: Create Release | |
needs: build | |
if: github.event_name != 'pull_request' && startswith(github.ref, 'refs/tags/v') | |
runs-on: ubuntu-latest | |
permissions: write-all | |
outputs: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
steps: | |
- name: release | |
uses: actions/create-release@v1 | |
id: create_release | |
with: | |
draft: false | |
prerelease: false | |
release_name: ${{ env.MINVERVERSIONOVERRIDE }} | |
tag_name: ${{ github.ref }} | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
publish: | |
name: Publish binaries | |
needs: release | |
permissions: write-all | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
target_arch: [amd64, arm, arm64] | |
exclude: | |
- os: windows-latest | |
target_arch: arm | |
- os: windows-latest | |
target_arch: arm64 | |
- os: macOS-latest | |
target_arch: arm | |
if: github.event_name != 'pull_request' && startswith(github.ref, 'refs/tags/v') | |
env: | |
ARTIFACT_DIR: ${{ github.workspace }}/release | |
PROJECT_NAME: azqr | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v2 | |
- name: Artifact Name linux & mac | |
if: matrix.target_os != 'windows' | |
run: | | |
echo AZQR_ARTIFACT_NAME=${{ env.PROJECT_NAME }}-${{ matrix.os }}-${{ matrix.target_arch }} >> $GITHUB_ENV | |
- name: Artifact Name windows | |
if: matrix.target_os == 'windows' | |
run: | | |
echo AZQR_ARTIFACT_NAME=${{ env.PROJECT_NAME }}-${{ matrix.os }}-${{ matrix.target_arch }} >> $env:GITHUB_ENV | |
- name: download artifacts - ${{ env.AZQR_ARTIFACT_NAME }} | |
uses: actions/download-artifact@master | |
with: | |
name: ${{ env.AZQR_ARTIFACT_NAME }} | |
path: ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}/ | |
- name: Create sha256 Checksums for linux and mac | |
if: matrix.os != 'windows-latest' | |
run: | | |
sha256sum ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}/azqr > ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}.sha256 | |
- name: Create sha256 Checksums for windows | |
if: matrix.os == 'windows-latest' | |
run: | | |
sha256sum ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}/azqr.exe > ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}.exe.sha256 | |
- name: upload linux & mac artifacts | |
if: matrix.os != 'windows-latest' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
upload_url: ${{ needs.release.outputs.upload_url }} | |
asset_path: ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}/azqr | |
asset_name: ${{ env.AZQR_ARTIFACT_NAME }} | |
asset_content_type: application/octet-stream | |
- name: upload linux & mac sha256 | |
if: matrix.os != 'windows-latest' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
upload_url: ${{ needs.release.outputs.upload_url }} | |
asset_path: ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}.sha256 | |
asset_name: ${{ env.AZQR_ARTIFACT_NAME }}.sha256 | |
asset_content_type: application/octet-stream | |
- name: upload windows artifact | |
if: matrix.os == 'windows-latest' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
upload_url: ${{ needs.release.outputs.upload_url }} | |
asset_path: ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}/azqr.exe | |
asset_name: ${{ env.AZQR_ARTIFACT_NAME }}.exe | |
asset_content_type: application/octet-stream | |
- name: upload windows sha256 | |
if: matrix.os == 'windows-latest' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
upload_url: ${{ needs.release.outputs.upload_url }} | |
asset_path: ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}.exe.sha256 | |
asset_name: ${{ env.AZQR_ARTIFACT_NAME }}.exe.sha256 | |
asset_content_type: application/octet-stream | |
- name: Setup .NET Core | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: 6.0.x | |
- name: Setup MinVer | |
run: | | |
dotnet tool install --global minver-cli --version 4.2.0 | |
- name: Calculate Version | |
run: | | |
echo "MINVERVERSIONOVERRIDE=$($HOME/.dotnet/tools/minver -t v. -m 0.1 -d preview)" >> $GITHUB_ENV | |
- name: Trigger Bump Winget | |
uses: peter-evans/repository-dispatch@v2 | |
with: | |
event-type: bump-winget | |
client-payload: '{"version": "${{ env.MINVERVERSIONOVERRIDE }}"}' | |
bump-winget: | |
name: bump-winget | |
needs: publish | |
permissions: write-all | |
if: github.event_name != 'pull_request' && startswith(github.ref, 'refs/tags/v') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup .NET Core | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: 6.0.x | |
- name: Setup MinVer | |
run: | | |
dotnet tool install --global minver-cli --version 4.2.0 | |
- name: Calculate Version | |
run: | | |
echo "MINVERVERSIONOVERRIDE=$($HOME/.dotnet/tools/minver -t v. -m 0.1 -d preview)" >> $GITHUB_ENV | |
- name: Trigger Bump Winget | |
uses: peter-evans/repository-dispatch@v2 | |
with: | |
event-type: bump-winget | |
client-payload: '{"version": "${{ env.MINVERVERSIONOVERRIDE }}"}' |