From 983ad0202676b04d8c199ea440ecd4dc4059eb51 Mon Sep 17 00:00:00 2001 From: circa10a Date: Sun, 11 Dec 2022 10:07:16 -0600 Subject: [PATCH] use gh actions for testing, releasing --- .drone.yml | 57 ---------------------------------- .github/workflows/build.yaml | 19 ++++++++++++ .github/workflows/release.yaml | 30 ++++++++++++++++++ .github/workflows/tag.yaml | 52 +++++++++++++++++++++++++++++++ .goreleaser.yaml | 27 ++++++++++++++++ README.md | 5 ++- 6 files changed, 130 insertions(+), 60 deletions(-) delete mode 100644 .drone.yml create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/tag.yaml create mode 100644 .goreleaser.yaml diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 98c4ad5..0000000 --- a/.drone.yml +++ /dev/null @@ -1,57 +0,0 @@ ---- -kind: pipeline -name: default - -platform: - os: linux - arch: amd64 - -workspace: - base: /go - path: src/github.com/metalmatze/digitalocean_exporter - -steps: -- name: build - pull: always - image: golang:alpine - commands: - - apk add -U git make - - make build - - make test - - make vet - - make lint - -- name: release - image: golang:alpine - commands: - - apk add -U git make - - make release - when: - event: - - tag - -- name: docker - image: plugins/docker - settings: - repo: metalmatze/digitalocean_exporter - tag: [ '0.6.1', '0.6' ] - environment: - DOCKER_PASSWORD: - from_secret: docker_password - DOCKER_USERNAME: - from_secret: docker_username - when: - event: - - tag - -- name: github - image: plugins/github-release - settings: - files: dist/* - environment: - GITHUB_TOKEN: - from_secret: github_token - when: - event: - - tag - diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..d36da7c --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,19 @@ +name: build +on: [ + push, + pull_request +] +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v2 + - name: Checkout code + uses: actions/checkout@v2 + - name: build + run: | + make build + make test + make vet + make lint \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..2147062 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,30 @@ +name: GoReleaser +on: + workflow_run: + workflows: ["Bump Git/Docker Version"] + branches: [master] + types: + - completed +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Unshallow + run: git fetch --prune --unshallow + - id: vars + run: | + echo ::set-output name=go_version::$(curl -s https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json | grep -oE '"version": "[0-9]{1}.[0-9]{1,}(.[0-9]{1,})?"' | head -1 | cut -d':' -f2 | sed 's/ //g; s/"//g') + echo "Using Go version ${{ steps.vars.outputs.go_version }}" + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ steps.vars.outputs.go_version }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml new file mode 100644 index 0000000..eba23ca --- /dev/null +++ b/.github/workflows/tag.yaml @@ -0,0 +1,52 @@ +name: Bump Git/Docker Version +on: + push: + branches: + - master +env: + PLATFORMS: linux/arm/v7,linux/amd64,linux/arm64, windows/amd64, darwin/amd64 + +jobs: + semver: + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.tagging.outputs.new_tag }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: '0' + - name: Bump version and push tag + uses: anothrNick/github-tag-action@1.39.0 + id: tagging + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + RELEASE_BRANCHES: master + DEFAULT_BUMP: minor + docker: + runs-on: ubuntu-latest + needs: semver + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.docker_username }} + password: ${{ secrets.docker_password }} + - name: Build and push latest + id: docker_build_latest + uses: docker/build-push-action@v2 + with: + push: true + tags: ${{ github.repository }}:latest + platforms: ${{ env.PLATFORMS }} + - name: Build and push versioned + id: docker_build_versioned + uses: docker/build-push-action@v2 + with: + push: true + tags: ${{ github.repository }}:${{ needs.semver.outputs.tag }} + platforms: ${{ env.PLATFORMS }} \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..70b809c --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,27 @@ +# Visit https://goreleaser.com for documentation on how to customize this +# behavior. +before: + hooks: + - go mod tidy +builds: +- env: + # goreleaser does not work with CGO, it could also complicate + # usage by users in CI/CD systems like Terraform Cloud where + # they are unable to install libraries. + - CGO_ENABLED=0 + mod_timestamp: '{{ .CommitTimestamp }}' + flags: + - -trimpath + ldflags: + - '-s -w -X main.Version={{.Version}} -X main.Commit={{.Commit}}' + goos: + - linux + goarch: + - amd64 + binary: '{{ .ProjectName }}_v{{ .Version }}' +archives: + - format: binary + name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' +changelog: + skip: false + sort: asc \ No newline at end of file diff --git a/README.md b/README.md index 55be242..26767e0 100755 --- a/README.md +++ b/README.md @@ -16,15 +16,14 @@ To deploy directly onto digitalocean, click the button below. #### Docker ```bash -docker pull metalmatze/digitalocean_exporter:0.6.1 -docker run --rm -p 9212:9212 -e DIGITALOCEAN_TOKEN=XXX metalmatze/digitalocean_exporter:0.6.1 +docker run --rm -p 9212:9212 -e DIGITALOCEAN_TOKEN=XXX metalmatze/digitalocean_exporter ``` Example `docker-compose.yml` with Transmission also running in docker. ```yaml digitalocean_exporter: - image: metalmatze/digitalocean_exporter:0.6.1 + image: metalmatze/digitalocean_exporter environment: - '-do.token=XXX' restart: always