From 1d105461eb1f8bb7732d6b6758a20d407c4e4a6f Mon Sep 17 00:00:00 2001 From: Devon Mar Date: Tue, 25 Jan 2022 14:06:45 -0800 Subject: [PATCH] Add goreleaser and cache --- .github/workflows/docker.yml | 30 ------------------ .github/workflows/release.yml | 59 +++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 8 +++++ .gitignore | 2 ++ .goreleaser.yaml | 31 ++++++++++++++++++ 5 files changed, 100 insertions(+), 30 deletions(-) delete mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 02a2832..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -"on": - push: - branches: - - master - -name: Docker build -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - platforms: linux/amd64,linux/arm64 - tags: devonm/radius-exporter:latest - push: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7f198b6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,59 @@ +--- +"on": + push: + tags: + - "v*" + +name: release +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0s + + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: "1.17" + + - name: Cache Go modules + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + if: success() && startsWith(github.ref, 'refs/tags/') + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + docker: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64,linux/arm64 + tags: devonm/radius-exporter:latest + push: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eb262bf..2b7af24 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,6 +14,14 @@ jobs: with: go-version: "1.17" + - name: Cache Go modules + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: fmt check run: test -z $(gofmt -l .) diff --git a/.gitignore b/.gitignore index 39110b3..246ef2b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ radius-exporter radius-exporter_* /config.yml + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..df1502b --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,31 @@ +--- +project_name: radius-exporter +builds: + - env: + - CGO_ENABLED=0 + ldflags: -X main.exporterVersion=v{{.Version}} -X main.exporterSha={{.Commit}} + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm + - arm64 + ignore: + - goos: windows + goarch: arm +archives: + - format: binary +release: + mode: append +checksum: + name_template: "checksums.txt" +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:"