Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

paved tagpr powered automated release flow #47

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/actions/release/actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: release
description: release executables

inputs:
tag:
description: check out the tag if not empty
default: ''
token:
description: GitHub token
required: true

runs:
using: composite

steps:
- uses: actions/checkout@v3
name: "Check out tag ${{ inputs.tag }}"
if: "inputs.tag != ''"
with:
ref: refs/tags/${{ inputs.tag }}
env:
GITHUB_TOKEN: ${{ inputs.token }}

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.18
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ inputs.token }}
19 changes: 0 additions & 19 deletions .github/release-drafter.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
changelog:
exclude:
labels:
- release-note/skip
- tagpr
categories:
- title: "💣 Breaking Changes"
labels:
- release-note/breaking-change
- title: "🚀 Features"
labels:
- release-note/feature
- title: "🐛 Bug Fixes"
labels:
- release-note/bugfix
- title: "📜 Documentation"
labels:
- release-note/document
- title: "🧰 Maintenance"
labels:
- release-note/chore
- title: "🔬 Other Changes"
labels:
- "*"
87 changes: 44 additions & 43 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,64 @@ on:

jobs:

test:
name: Test
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.18
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get dependencies
run: go mod download
- name: Get Devtools
run: make setup
- name: Lint
run : make lint

test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.18
- name: Get Devtools
run: make setup
- name: Build
run: make
run: make build-only
- name: Test
run: make test
- name: E2E Test
run: make e2e
- name: Validate .goreleaser.yml
uses: goreleaser/goreleaser-action@v2

integration:
name: Integration Test
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
version: latest
args: release --snapshot --skip-publish --rm-dist --debug
go-version: ~1.18
- name: Get Devtools
run: make setup
- name: integration test
run: make integration

image_build:
name: Image Build
validate-goreleaser:
name: Validate GoReleaser
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: 1
IMAGE_PREFIX: ghcr.io/${{ github.repository_owner }}/
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.18
id: go
- name: Check out
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get Devtools
run: make setup
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
run: make build-image
- name: Push Docker image
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: make push-image
- name: Check out
uses: actions/checkout@v3
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.18
- name: Validate GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
args: release --snapshot --skip-publish --rm-dist --debug
75 changes: 8 additions & 67 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,76 +1,17 @@
name: Release
name: Release By Tagged Manually
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
image_build:
name: Release Docker Image
release:
name: Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
env:
RELEASE: "true"
DOCKER_BUILDKIT: 1
IMAGE_PREFIX: ghcr.io/${{ github.repository_owner }}/
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16
id: go
- name: Check out
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get Devtools
run: make setup
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
run: make build-image
- name: Push Docker image
run: make push-image

goreleaser:
name: Release Binaries
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
env:
RELEASE: "true"
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.18
id: go
- name: Check out
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get Devtools
run: make setup
- name: Get dependencies
run: go mod download
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

update_release_draft:
name: Draft Release Note
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
env:
RELEASE: "true"
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check out
uses: actions/checkout@v3
- uses: ./.github/actions/release
with:
token: ${{ secrets.GITHUB_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/tagpr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: tagpr
on:
push:
branches: ["master"]

jobs:
tagpr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: tagpr
name: Tagpr
uses: Songmu/tagpr@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# If tagpr pushed tags, invoke release custom action manually.
# It is because:
# > When you use the repository's GITHUB_TOKEN to perform tasks,
# > events triggered by the GITHUB_TOKEN, with the exception of
# > workflow_dispatch and repository_dispatch, will not create
# > a new workflow run.
# ref: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow
- name: "Release (only when tagged)"
uses: ./.github/actions/release
if: "steps.tagpr.outputs.tag != ''"
with:
tag: ${{ steps.tagpr.outputs.tag }}
token: ${{ secrets.GITHUB_TOKEN }}
42 changes: 40 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,45 @@ builds:
- netgo
ldflags:
- -s -w -X github.com/everpeace/kube-throttler/cmd.Version={{.Version}} -X github.com/everpeace/kube-throttler/cmd.Revision={{.ShortCommit}} -extldflags "-static"
# changelog will be generated by release drafter
# see .github/release-drafter.yml

dockers:
- image_templates: ["ghcr.io/everpeace/{{ .ProjectName }}:{{ .Version }}-amd64"]
dockerfile: Dockerfile.release
goarch: amd64
use: buildx
build_flag_templates:
- --platform=linux/amd64
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/everpeace/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/everpeace/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.revision={{ .ShortCommit }}
- --label=org.opencontainers.image.licenses=Apache-2.0
- image_templates: ["ghcr.io/everpeace/{{ .ProjectName }}:{{ .Version }}-arm64v8"]
dockerfile: Dockerfile.release
goarch: arm64
use: buildx
build_flag_templates:
- --platform=linux/arm64/v8
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/everpeace/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/everpeace/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.revision={{ .ShortCommit }}
- --label=org.opencontainers.image.licenses=Apache-2.0

docker_manifests:
- name_template: ghcr.io/everpeace/{{ .ProjectName }}:{{ .Version }}
image_templates:
- ghcr.io/everpeace/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/everpeace/{{ .ProjectName }}:{{ .Version }}-arm64v8
- name_template: ghcr.io/everpeace/{{ .ProjectName }}:latest
image_templates:
- ghcr.io/everpeace/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/everpeace/{{ .ProjectName }}:{{ .Version }}-arm64v8

# change log will be generated by tagpr
changelog:
skip: true
5 changes: 5 additions & 0 deletions Dockerfile.release
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM debian:bullseye-slim
WORKDIR /
COPY kube-throttler /usr/local/bin/kube-throttler
ENTRYPOINT ["/usr/local/bin/kube-throttler"]
CMD ["kube-scheduler"]
Loading