Skip to content

Commit ebe1554

Browse files
authored
Merge pull request #2 from Kong/feat/github-releases
feat(releases): setup github releases
2 parents 0b42aa4 + 9ed092d commit ebe1554

File tree

8 files changed

+214
-6
lines changed

8 files changed

+214
-6
lines changed

.github/template-sync.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
---
22
additional:
3-
- anchore-helm
4-
- docker-fpm
5-
- lacework-manifest
6-
- kong-build-tools-base-images
7-
- kong-internal-unstable-helm
8-
93

104
files:
115
- '!README.md'
@@ -16,3 +10,9 @@ files:
1610
- '!.github/PULL_REQUEST_TEMPLATE.md'
1711
- '!**/CODEOWNERS'
1812
- '!.yamllint'
13+
- '!Dockerfile'
14+
- '!build.sh'
15+
- '!test.sh'
16+
- .github/workflows/release.yaml
17+
- .releaserc
18+
- Makefile

.github/workflows/release.yaml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
name: Release
3+
4+
on: # yamllint disable-line rule:truthy
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
release:
12+
name: Create Release
13+
runs-on: ubuntu-latest
14+
outputs:
15+
published: ${{ steps.release.outputs.published }}
16+
release-git-tag: ${{ steps.release.outputs.release-git-tag }}
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
- name: Release
21+
id: release
22+
uses: ahmadnassri/[email protected]
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
26+
artifacts:
27+
needs: release
28+
name: Create Release Artifacts
29+
strategy:
30+
matrix:
31+
architecture: [aarch64, x86_64]
32+
ostype: [linux-gnu, linux-musl]
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v3
36+
- uses: docker/setup-qemu-action@v2
37+
- uses: docker/setup-buildx-action@v2
38+
- name: Set environment variables
39+
run: |
40+
echo "ARCHITECTURE=${{ matrix.architecture }}" >> $GITHUB_ENV
41+
echo "OSTYPE=${{ matrix.ostype }}" >> $GITHUB_ENV
42+
echo "REGISTRY=ghcr.io"
43+
- name: Build, and Package
44+
run: make build/package
45+
- name: Log in to the Container registry
46+
if: ${{ needs.release.outputs.published == 'true' }}
47+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
48+
with:
49+
registry: ghcr.io
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
- name: Docker meta
53+
if: ${{ needs.release.outputs.published == 'true' }}
54+
id: meta
55+
uses: docker/metadata-action@v4
56+
with:
57+
images: ghcr.io/kong/template-github-release
58+
sep-tags: ' '
59+
flavor: |
60+
suffix=-${{ matrix.architecture }}-${{ matrix.ostype }}
61+
tags: |
62+
type=sha
63+
type=ref,event=branch
64+
type=semver,value=${{ needs.release.outputs.release-git-tag }}
65+
- name: Retag and Push
66+
if: ${{ needs.release.outputs.published == 'true' }}
67+
run: |
68+
for tag in ${{ steps.meta.outputs.tags }}; do \
69+
docker tag ghcr.io/template-github-release:build-$ARCHITECTURE-$OSTYPE $tag && \
70+
docker push $tag; \
71+
done
72+
- name: Archive the package
73+
if: ${{ needs.release.outputs.published == 'true' }}
74+
run: |
75+
tar -C package -czvf ${{ matrix.architecture }}-${{ matrix.ostype }}.tar.gz .
76+
- name: Add Release Artifact to the Github Release
77+
if: ${{ needs.release.outputs.published == 'true' }}
78+
uses: softprops/action-gh-release@v1
79+
with:
80+
tag_name: ${{ needs.release.outputs.release-git-tag }}
81+
files: ${{ matrix.architecture }}-${{ matrix.ostype }}.tar.gz

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package

.releaserc

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"branches": ["main"],
3+
"tagFormat": "${version}",
4+
"repositoryUrl": "https://github.com/kong/template-github-release.git",
5+
"plugins": [
6+
[
7+
"@semantic-release/commit-analyzer",
8+
{
9+
"preset": "conventionalcommits",
10+
"releaseRules": [
11+
{ "breaking": true, "release": "major" },
12+
{ "revert": true, "release": "patch" },
13+
{ "type": "build", "release": "patch" },
14+
{ "type": "docs", "release": "patch" },
15+
{ "type": "feat", "release": "minor" },
16+
{ "type": "fix", "release": "patch" },
17+
{ "type": "perf", "release": "patch" },
18+
{ "type": "refactor", "release": "patch" },
19+
{ "type": "chore", "release": "patch" }
20+
]
21+
}
22+
],
23+
[
24+
"@semantic-release/release-notes-generator",
25+
{
26+
"preset": "conventionalcommits",
27+
"presetConfig": {
28+
"types": [
29+
{ "type": "build", "section": "Build", "hidden": false },
30+
{ "type": "chore", "section": "Chores", "hidden": false },
31+
{ "type": "ci", "section": "CI/CD", "hidden": false },
32+
{ "type": "docs", "section": "Docs", "hidden": false },
33+
{ "type": "feat", "section": "Features", "hidden": false },
34+
{ "type": "fix", "section": "Bug Fixes", "hidden": false },
35+
{ "type": "perf", "section": "Performance", "hidden": false },
36+
{ "type": "refactor", "section": "Refactor", "hidden": false },
37+
{ "type": "style", "section": "Code Style", "hidden": false },
38+
{ "type": "test", "section": "Tests", "hidden": false }
39+
]
40+
}
41+
}
42+
],
43+
"@semantic-release/github"
44+
]
45+
}

Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
ARG OSTYPE=linux-gnu
2+
ARG ARCHITECTURE=x86_64
3+
ARG DOCKER_REGISTRY=ghcr.io
4+
ARG DOCKER_IMAGE_NAME
5+
6+
# List out all image permutations to trick dependabot
7+
FROM --platform=linux/amd64 kong/kong-build-tools:apk-1.8.1 as x86_64-linux-musl
8+
FROM --platform=linux/amd64 kong/kong-build-tools:rpm-1.8.1 as x86_64-linux-gnu
9+
FROM --platform=linux/arm64 kong/kong-build-tools:apk-1.8.1 as aarch64-linux-musl
10+
FROM --platform=linux/arm64 kong/kong-build-tools:rpm-1.8.1 as aarch64-linux-gnu
11+
12+
13+
# Run the build script
14+
FROM $ARCHITECTURE-$OSTYPE as build
15+
16+
COPY . /src
17+
RUN /src/build.sh && /src/test.sh
18+
19+
20+
# Copy the build result to scratch so we can export the result
21+
FROM scratch as package
22+
23+
COPY --from=build /tmp/build /

Makefile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
ARCHITECTURE ?= x86_64
2+
OSTYPE ?= linux-gnu
3+
DOCKER_TARGET ?= build
4+
DOCKER_REGISTRY ?= ghcr.io
5+
DOCKER_IMAGE_NAME ?= template-github-release
6+
DOCKER_IMAGE_TAG ?= $(DOCKER_TARGET)-$(ARCHITECTURE)-$(OSTYPE)
7+
DOCKER_NAME ?= $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
8+
DOCKER_RESULT ?= --load
9+
10+
clean:
11+
rm -rf package
12+
docker rmi $(DOCKER_NAME)
13+
14+
docker:
15+
docker buildx build \
16+
--build-arg DOCKER_REGISTRY=$(DOCKER_REGISTRY) \
17+
--build-arg DOCKER_IMAGE_NAME=$(DOCKER_IMAGE_NAME) \
18+
--build-arg DOCKER_IMAGE_TAG=$(DOCKER_IMAGE_TAG) \
19+
--build-arg ARCHITECTURE=$(ARCHITECTURE) \
20+
--build-arg OSTYPE=$(OSTYPE) \
21+
--target=$(DOCKER_TARGET) \
22+
-t $(DOCKER_NAME) \
23+
$(DOCKER_RESULT) .
24+
25+
build/docker:
26+
docker inspect --format='{{.Config.Image}}' $(DOCKER_NAME) || \
27+
$(MAKE) DOCKER_TARGET=build docker
28+
29+
build/package: build/docker
30+
$(MAKE) DOCKER_TARGET=package DOCKER_RESULT="-o package" docker

build.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
IFS=$'\n\t'
5+
6+
if [ -n "${DEBUG:-}" ]; then
7+
set -x
8+
fi
9+
10+
function main() {
11+
rm -rf /tmp/build/* && uname -a >> /tmp/build/out
12+
}
13+
14+
main

test.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
IFS=$'\n\t'
5+
6+
if [ -n "${DEBUG:-}" ]; then
7+
set -x
8+
fi
9+
10+
function test() {
11+
ls -lah /tmp/build/out
12+
}
13+
14+
test

0 commit comments

Comments
 (0)