From edd6e98ee7d8dee45f8175817a4943974876d2df Mon Sep 17 00:00:00 2001 From: bl4ko Date: Wed, 7 Feb 2024 10:38:59 +0100 Subject: [PATCH] Adding github actions workflows --- .github/workflows/cd.yml | 45 +++++++++++++++++++++++ .github/workflows/ci.yml | 61 ++++++++++++++++++++++++++++++++ go.mod | 2 +- cronjob.yaml => k8s/cronjob.yaml | 0 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/ci.yml rename cronjob.yaml => k8s/cronjob.yaml (100%) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000..15c0a5e8 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,45 @@ +name: Deploy image to ghcr.io + +on: + push: + branches: + - main + paths: + - cmd/** + - internal/** + - pkg/** + - Dockerfile + - .dockerignore + - .golangci.yml + - go.mod + - go.sum + +jobs: + build_and_push: + runs-on: ubuntu-latest + steps: + + - name: Login to dockerhub + uses: docker/login-action@v3 + with: + username: bl4ko + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to ghcr.io + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: bl4ko + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push final image + uses: docker/build-push-action@v5.1.0 + with: + platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v6,linux/arm/v7,linux/ppc64le + labels: ${{ steps.meta.outputs.labels }} + build-args: | + CREATED=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} + COMMIT=${{ steps.shortcommit.outputs.value }} + VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} + tags: ${{ steps.meta.outputs.tags }} + push: true \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..0f303f9d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,61 @@ +name: Run tests and upload results + +on: + push: + branches: + - main + - develop + paths: + - cmd/** + - internal/** + - .dockerignore + - .golangci.yml + - go.mod + - go.sum + pull_request: + branches: + - main + - develop + paths: + - cmd/** + - internal/** + - .dockerignore + - .golangci.yml + - go.mod + - go.sum + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: ["1.19", "1.20", "1.21.x"] + + steps: + - uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Require: The version of golangci-lint to use. + # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. + # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. + version: v1.54 + + - name: Install dependencies + run: go get . + + - name: Test with Go + run: go test ./... -json > TestResults-${{ matrix.go-version }}.json + + - name: Upload Go test results + uses: actions/upload-artifact@v4 + with: + name: Go-results-${{ matrix.go-version }} + path: TestResults-${{ matrix.go-version }}.json + diff --git a/go.mod b/go.mod index ba695288..f0d09d34 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/bl4ko/netbox-ssot -go 1.21.4 +go 1.21 require ( github.com/ovirt/go-ovirt v4.3.4+incompatible // indirect diff --git a/cronjob.yaml b/k8s/cronjob.yaml similarity index 100% rename from cronjob.yaml rename to k8s/cronjob.yaml