Skip to content

Commit

Permalink
Merge branch 'chore/refactor-ci'
Browse files Browse the repository at this point in the history
  • Loading branch information
jmriebold committed Aug 9, 2023
2 parents ed60492 + c29fb76 commit 439d3f3
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 119 deletions.
31 changes: 21 additions & 10 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,64 @@
on: push
name: Build

on: push

jobs:
build-go:
name: Build Go

runs-on: ${{ matrix.os }}

strategy:
matrix:
go-version: [1.21.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Install Go
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Create Cache
- name: Create cache
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Checkout code
- name: Checkout
uses: actions/checkout@v3
- name: build

- name: Build
run: go build
if: steps.cache.outputs.cache-hit != 'true'

build-docker:
name: Build Docker

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx

- name: Set up Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers

- name: Populate cache
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build
id: docker_build
uses: docker/build-push-action@v4
with:
push: false
tags: jmriebold/sqs-prometheus-exporter:latest
tags: ghcr.io/${{ github.repository }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
48 changes: 41 additions & 7 deletions .github/workflows/code-quality.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
name: code-quality
name: Lint

on:
push:

permissions:
contents: read

jobs:
golangci:
name: lint
lint-go:
name: Lint code

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: golangci-lint

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
version: latest

lint-chart:
name: Lint chart

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.12.1

- name: Set up chart-testing
uses: helm/chart-testing-action@v2

- name: Test chart
id: list-changed
run: |
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
if [[ -n "$changed" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
63 changes: 0 additions & 63 deletions .github/workflows/release-chart.yaml

This file was deleted.

107 changes: 69 additions & 38 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,90 +1,121 @@
name: Release

on:
release:
types: [published]

name: Build Release
jobs:
release-bins:
name: Release Go Binary
name: Release Go

runs-on: ubuntu-latest

strategy:
matrix:
goos: [linux, windows, darwin]
goarch: [amd64]

steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/go-release-action@v1
- name: Checkout
uses: actions/checkout@v3

- name: Release
uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "1.21"
goversion: "1.21.0"
extra_files: LICENSE README.md

release-docker:
name: Release Docker

runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=jmriebold/sqs-prometheus-exporter
VERSION=${GITHUB_REF#refs/tags/v}
TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:latest"
echo ::set-output name=tags::${TAGS}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers

- name: Populate cache
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=ghcr.io/${GITHUB_REPOSITORY}
VERSION=${GITHUB_REF#refs/tags/v}
TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:latest"
echo ::set-output name=tags::${TAGS}
- name: Log in
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Release
uses: docker/build-push-action@v4
with:
push: true
tags: ${{ steps.prep.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

name: Create and publish a Docker image
release-chart:
name: Release chart

release-docker-gh:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
contents: write # to push chart release and create a release (helm/chart-releaser-action)
packages: write # needed for ghcr access
id-token: write # needed for keyless signing

steps:
- name: Checkout repository
- name: Checkout
uses: actions/checkout@v3

- name: Log in to the Container registry
- name: Fetch
run: git fetch --prune --unshallow

- name: Configure Git
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.9.2

- name: Set up cosign-installer
uses: sigstore/cosign-installer@v3

- name: Log in
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Release
env:
REPO_NAME: ${{ github.event.repository.name }}
run: |
cd chart
helm package ${REPO_NAME}
helm push *.tgz "oci://ghcr.io/${GITHUB_REPOSITORY_OWNER}/charts"
2 changes: 1 addition & 1 deletion chart/sqs-prometheus-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ app:
name: sqs-prometheus-exporter

image:
repository: jmriebold/sqs-prometheus-exporter
repository: ghcr.io/jmriebold/sqs-prometheus-exporter
tag: 1.0.5

deployment:
Expand Down

0 comments on commit 439d3f3

Please sign in to comment.