Skip to content

Commit b703611

Browse files
committed
chore(ci): setup continuous delivery workflow
1 parent 8bdb618 commit b703611

File tree

4 files changed

+129
-6
lines changed

4 files changed

+129
-6
lines changed

.github/workflows/release.yaml

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

.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

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ COPY . /src
1717
RUN /src/build.sh && /src/test.sh
1818

1919

20-
# COPY --from doesn't support args so use an intermediary image
21-
FROM $DOCKER_REGISTRY/$DOCKER_IMAGE_NAME:build-$ARCHITECTURE-$OSTYPE as build-result
22-
23-
2420
# Copy the build result to scratch so we can export the result
2521
FROM scratch as package
2622

27-
COPY --from=build-result /tmp/build /
23+
COPY --from=build /tmp/build /

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ DOCKER_NAME ?= $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
88
DOCKER_RESULT ?= --load
99

1010
clean:
11-
rm -rf *.tar.gz
11+
rm -rf package
1212
docker rmi $(DOCKER_NAME)
1313

1414
docker:

0 commit comments

Comments
 (0)