Merge pull request #149 from datarootsio/dependabot/github_actions/go… #342
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: ci | |
on: | |
push: | |
jobs: | |
golangci: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: '0' | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: "^1.20" | |
- uses: golangci/[email protected] | |
tests: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: '0' | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: "^1.20" | |
- name: run tests on cmd | |
run: go test ./cmd | |
- name: run tests on pkg | |
run: go test ./pkg -timeout 120s -coverprofile=cover.out -covermode=atomic | |
- uses: codecov/codecov-action@v3 | |
with: | |
files: ./cover.out | |
version_tag: | |
needs: | |
- tests | |
- golangci | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
outputs: | |
new_tag: ${{ steps.tag_action.outputs.new_tag }} | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: '0' | |
- name: Bump version and push tag | |
id: tag_action | |
uses: anothrNick/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
WITH_V: true | |
DEFAULT_BUMP: patch | |
build: | |
needs: version_tag | |
runs-on: ubuntu-latest | |
## need decent versioning strategy in future | |
if: github.ref == 'refs/heads/main' | |
env: | |
CGO_ENABLED: 0 | |
strategy: | |
matrix: | |
goos: [linux, darwin] | |
goarch: ["386", amd64, arm64] | |
exclude: | |
- goarch: "386" | |
goos: darwin | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: '0' | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: "^1.16" | |
## above is fine to get latest for now, also save a copy with short sha | |
- id: vars | |
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" | |
- run: mkdir -p ${{ matrix.goos }}/${{ matrix.goarch }} | |
- run: env GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-X 'github.com/datarootsio/cheek/pkg.Version=${{ steps.vars.outputs.sha_short }}'" -o ${{ matrix.goos }}/${{ matrix.goarch }} | |
- run: cp ${{ matrix.goos }}/${{ matrix.goarch }}/cheek ${{ matrix.goos }}/${{ matrix.goarch }}/cheek-${{ steps.vars.outputs.sha_short }} | |
- run: cp ${{ matrix.goos }}/${{ matrix.goarch }}/cheek ${{ matrix.goos }}/${{ matrix.goarch }}/cheek-${{ needs.version_tag.outputs.new_tag }} | |
## upload binary to google storage | |
- id: auth | |
uses: google-github-actions/[email protected] | |
with: | |
credentials_json: ${{ secrets.gcp_credentials_cheek }} | |
- id: upload-files | |
uses: google-github-actions/[email protected] | |
with: | |
path: ${{ matrix.goos }}/${{ matrix.goarch }} | |
destination: cheek-scheduler/${{ matrix.goos }}/ | |
docker-build: | |
needs: | |
- build | |
- version_tag | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: '0' | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: | | |
ghcr.io/datarootsio/cheek:latest | |
ghcr.io/datarootsio/cheek:${{ needs.version_tag.outputs.new_tag }} |