Merge pull request #13 from vitwit/anil/fix_concurrency #11
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
# .github/workflows/go.yml | |
name: Go | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
permissions: | |
contents: read | |
pull-requests: write # needed for coverage comment | |
jobs: | |
test: | |
name: Test and Coverage | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # needed for git history | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
cache: true | |
- name: Install golangci-lint | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
version: latest | |
args: --timeout=5m | |
- name: Verify dependencies | |
run: go mod verify | |
- name: Format check | |
run: | | |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then | |
echo "The following files are not formatted correctly:" | |
gofmt -s -l . | |
exit 1 | |
fi | |
- name: Run go vet | |
run: go vet ./... | |
- name: Run tests with coverage | |
run: | | |
go test -race -coverprofile=coverage.txt -covermode=atomic -v ./... | |
go tool cover -func=coverage.txt | |
# - name: Upload coverage to Codecov | |
# uses: codecov/codecov-action@v3 | |
# with: | |
# files: ./coverage.txt | |
# fail_ci_if_error: true | |
# verbose: true | |
- name: Generate coverage report | |
run: | | |
go tool cover -html=coverage.txt -o coverage.html | |
- name: Save coverage report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: coverage-report | |
path: coverage.html | |
# - name: Comment coverage on PR | |
# uses: codecov/codecov-action@v3 | |
# with: | |
# files: ./coverage.txt | |
# fail_ci_if_error: true | |
# verbose: true | |
# token: ${{ secrets.CODECOV_TOKEN }} | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
needs: test | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
cache: true | |
- name: Build | |
run: | | |
GOOS=linux GOARCH=amd64 go build -o bin/cosmoscope-linux-amd64 ./cmd/cosmoscope | |
GOOS=darwin GOARCH=amd64 go build -o bin/cosmoscope-darwin-amd64 ./cmd/cosmoscope | |
GOOS=windows GOARCH=amd64 go build -o bin/cosmoscope-windows-amd64.exe ./cmd/cosmoscope | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: binaries | |
path: bin/ | |
release: | |
name: Create Release | |
runs-on: ubuntu-latest | |
needs: build | |
if: startsWith(github.ref, 'refs/tags/') | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: binaries | |
path: bin | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: | | |
bin/cosmoscope-linux-amd64 | |
bin/cosmoscope-darwin-amd64 | |
bin/cosmoscope-windows-amd64.exe | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |