Skip to content

Commit

Permalink
chore(ci): add new ci jobs for docker builds & changelogs (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukowa authored Oct 13, 2022
1 parent 7cd5d19 commit 4ba2e16
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 39 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!main.go
!go.mod
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
interval: "weekly"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "monthly"
interval: "weekly"
46 changes: 46 additions & 0 deletions .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Detect Changes

# todo change branch main
on:
push:
branches:
- "main"

jobs:

detect-changes:
runs-on: ubuntu-latest

steps:

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

# https://github.com/tj-actions/changed-files/blob/main/README.md#inputs
-
name: Detect Changes
uses: tj-actions/changed-files@v32.1.0
id: changes
with:
files: |
*.go
*.mod
*Dockerfile
# Makefile
-
name: Generate Changelog
run: make generate-changelog-ci
if: steps.changes.outputs.any_changed == 'true'

# https://github.com/peter-evans/create-pull-request#action-inputs
-
name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: "${{ secrets.GITHUB_TOKEN }}"
branch: "change/${{ github.sha }}"
commit-message: "new changes"
title: "maybe new release?"
126 changes: 126 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Build and Push Docker Images

on:
push:
branches:
- "*"
tags:
- "*"

jobs:

Docker:
name: Build and Push Docker Images
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}

steps:

-
name: Checkout
uses: actions/checkout@v3

-
name: Set up Docker Build
uses: docker/setup-buildx-action@v2

-
name: Build Docker Test Image
uses: docker/build-push-action@v3
id: build
with:
context: .
load: true
cache-from: type=gha
cache-to: type=gha,mode=max

-
name: Test Docker Image
run: |
CMD="docker run --rm -i -p 9001:9001 ${{ steps.build.outputs.imageid }} --port=9001" ./test.sh
- name: Get Docker Image Metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
quay.io/k8start/http-headers
ghcr.io/bukowa/http-headers
bukowa/http-headers
tags: |
type=schedule
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=ref,event=pr
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v2

- name: Login to Docker Hub Container Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ROBOT_TOKEN }}

- name: Login to GHCR.io Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Quay.io Container Registry
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}

# - name: Get Docker Expire Image Metadata
# id: meta-expire
# uses: docker/metadata-action@v4
# with:
# images: |
# quay.io/k8start/http-headers
# tags: |
# type=sha

# -
# # Push images that expire
# name: Build and Push Docker Expire Images
# uses: docker/build-push-action@v3
# with:
# context: .
# push: true
# tags: ${{ steps.meta-expire.outputs.tags }}
# labels: |
# quay.expires-after=72h
# ${{ steps.meta-expire.outputs.labels }}
# cache-from: |
# type=gha
# type=registry,ref=quay.io/k8start/http-headers
# cache-to: |
# type=gha,mode=max
# platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x

-
# Push other images
name: Build and Push Docker Images
uses: docker/build-push-action@v3
id: build-all
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: |
${{ steps.meta.outputs.labels }}
cache-from: |
type=gha
type=registry,ref=quay.io/k8start/http-headers
cache-to: |
type=gha,mode=max
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
36 changes: 0 additions & 36 deletions .github/workflows/test-applicaton.yaml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test

on:
pull_request:

jobs:

Docker:
name: Test in Docker
runs-on: ubuntu-latest
steps:

-
name: Checkout
uses: actions/checkout@v3

-
name: Set up Docker Build
uses: docker/setup-buildx-action@v2

-
name: Build Docker Test Image
uses: docker/build-push-action@v3
id: build
with:
context: .
load: true
cache-from: type=gha
cache-to: type=gha,mode=max

-
name: Test Docker Image
run: |
CMD="docker run --rm -i -p 9001:9001 ${{ steps.build.outputs.imageid }} --port=9001" ./test.sh
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
FROM golang:1.19-alpine as builder
COPY main.go .
ENV CGO_ENABLED=0
RUN go build -o /app main.go

FROM alpine
LABEL maintainer="github.com/bukowa"

# Define GOTRACEBACK to mark this container as using the Go language runtime
# for `skaffold debug` (https://skaffold.dev/docs/workflows/debug/).
ENV GOTRACEBACK=single
ENTRYPOINT ["./app"]
COPY --from=builder /app .

18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

generate-changelog:
./scripts/generate-changelog.sh

generate-changelog-ci:
touch CHANGELOG.md CHANGELOG.LATEST.md \
&& \
./scripts/generate-changelog.sh \
-u --prepend=CHANGELOG.md \
--include-path "*.go" \
--include-path "*.mod" \
--include-path "*Dockerfile" \
&& \
./scripts/generate-changelog.sh \
-u --output=CHANGELOG.LATEST.md \
--include-path "*.go" \
--include-path "*.mod" \
--include-path "*Dockerfile"
68 changes: 68 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# configuration file for git-cliff (0.1.0)

[changelog]
# changelog header
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""
# template for the changelog body
# https://tera.netlify.app/docs/#introduction
body = """
{% if version %}\
## [{{ version | trim_start_matches(pat="[-[:alpha:]]") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else %}\
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits %}
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message }}\
{% endfor %}
{% endfor %}\n
"""
# remove the leading and trailing whitespace from the template
trim = true
# changelog footer
footer = """
<!-- generated by git-cliff -->
"""

[git]
# parse the commits based on https://www.conventionalcommits.org
conventional_commits = true
# filter out the commits that are not conventional
filter_unconventional = false
# process each line of a commit as an individual commit
split_commits = false
# regex for preprocessing the commit messages
commit_preprocessors = [
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](https://github.com/bukowa/http-headers/issues/${2}))"},
]
# regex for parsing and grouping commits
commit_parsers = [
{ message = "^feat", group = "Features"},
{ message = "^fix", group = "Bug Fixes"},
{ message = "^doc", group = "Documentation"},
{ message = "^perf", group = "Performance"},
{ message = "^refactor", group = "Refactor"},
{ message = "^style", group = "Styling"},
{ message = "^test", group = "Testing"},
{ message = "^build", group = "Build"},
{ message = "^chore\\(release\\): prepare for", skip = true},
{ message = "^chore", group = "Miscellaneous Tasks"},
{ message = "^add", group = "Core"},
{ body = ".*security", group = "Security"},
]
# filter out the commits that are not matched by commit parsers
filter_commits = true
# glob pattern for matching git tags
tag_pattern = "[0-9].[0-9].[0-9].*"
# regex for skipping tags
skip_tags = "v0.1.0-beta.1"
# regex for ignoring tags
ignore_tags = ""
# sort the tags chronologically
date_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
18 changes: 18 additions & 0 deletions scripts/generate-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -eux

echo "Building docker image for git-cliff..."

GIT_CLIFF=$(docker build -q - <<EOF
FROM ghcr.io/orhun/git-cliff/git-cliff:sha-0f38960
WORKDIR /workdirvol
ENTRYPOINT ["git-cliff"]
EOF
)

echo "Running docker image for git-cliff..."
docker run --rm \
--volume="${PWD}:/workdirvol" \
-u "$(id -u)" \
"${GIT_CLIFF}" \
"$@"
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Header1: [header1]
Header2: [header2]
Host: [localhost:9001]'

printf "===\nResult:\n===\n$RESULT\n"; printf "Want:\n===\n$WANT\n";
printf "===\nResult:\n===\n$RESULT\n"; printf "===\nWant:\n===\n$WANT\n===\n";

if [[ "$RESULT" != "$WANT" ]]; then
printf "test failed"; exit 1
Expand Down

0 comments on commit 4ba2e16

Please sign in to comment.