Merge pull request #121 from doitintl/dependabot/go_modules/google.go… #82
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: build | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- '*' | |
tags: | |
- '*' | |
paths-ignore: | |
- 'docs/**' | |
- 'deploy/**' | |
- '*.md' | |
- '*.yaml' | |
- '*.sh' | |
pull_request: | |
branches: | |
- '*' | |
jobs: | |
validate: | |
runs-on: ubuntu-latest | |
if: ${{ !contains(github.event.head_commit.message,'[skip ci]') }} | |
container: golang:1.21-alpine | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: test | |
shell: sh | |
env: | |
CGO_ENABLED: 0 | |
run: | | |
apk --update add ca-certificates tzdata make git bash | |
make lint | |
make test-json | |
- name: upload test results | |
uses: actions/upload-artifact@v3 | |
if: ${{ always() }} | |
with: | |
name: test-reports | |
if-no-files-found: ignore | |
path: | | |
golangci-lint.out | |
test-report.out | |
coverage.out | |
- name: SonarCloud scan | |
uses: SonarSource/sonarcloud-github-action@master | |
if: ${{ always() }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
docker-build: | |
runs-on: ubuntu-latest | |
needs: validate | |
# build only on master branch and tags | |
if: ${{ !contains(github.event.head_commit.message,'[skip ci]') && (github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))) }} | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: get short sha | |
id: short_sha | |
run: echo ::set-output name=sha::$(git rev-parse --short HEAD) | |
- name: get version | |
id: version | |
run: echo ::set-output name=version::$([[ -z "${{ github.event.pull_request.number }}" ]] && echo "sha-${{ steps.short_sha.outputs.sha }}" || echo "pr-${{ github.event.pull_request.number }}") | |
- name: set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: set up Docker buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: login to DockerHub | |
if: ${{ github.event_name != 'pull_request' }} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: prepare meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ github.repository }}-agent | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
type=sha | |
labels: | | |
github.run.id=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
org.opencontainers.image.title=kubeip-agent | |
org.opencontainers.image.description=kubeip agent | |
org.opencontainers.image.vendor=DoiT International | |
- name: build and push | |
uses: docker/build-push-action@v5 | |
with: | |
build-args: | | |
VERSION=${{ steps.version.outputs.version }} | |
COMMIT=${{ steps.short_sha.outputs.sha }} | |
BRANCH=${{ github.ref_name }} | |
push: true | |
platforms: linux/amd64,linux/arm64 | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |