Skip to content

Commit 8180ec8

Browse files
authored
Publish to ghcr (#1)
* add some version and changelog automation
1 parent 0d19eea commit 8180ec8

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

.github/workflows/autorelease.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Stolen from https://github.com/mrchief/aws-creds-okta-action/blob/master/.github/workflows/autorelease.yml
2+
name: Auto Release
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- master
8+
jobs:
9+
github-release:
10+
if: github.event.pull_request.merged == true && contains(toJSON(github.event.pull_request.labels.*.name), '"autorelease"')
11+
runs-on: ubuntu-latest
12+
env:
13+
manifest_file: 'manifest.yml'
14+
changelog_file: 'CHANGELOG.md'
15+
outputs:
16+
version: ${{ steps.version.outputs.version }}
17+
steps:
18+
- uses: actions/checkout@v2
19+
with:
20+
ref: master
21+
- name: get version
22+
id: version
23+
run: |
24+
sed -n 's/^version:\s\(.*\)$/\1/p' ${{ env.manifest_file }} | xargs -I {} echo "::set-output name=version::{}"
25+
- name: get changelog
26+
id: changelog
27+
run: |
28+
changelog=$(echo "${{ steps.version.outputs.version}}" | xargs -I {} sed -n '/^#\s'"{}"'.*$/,/^#\s\([^[:space:]]\+\).*$/{//!p}' ${{ env.changelog_file }})
29+
echo $changelog
30+
changelog="${changelog//'%'/'%25'}"
31+
changelog="${changelog//$'\n'/'%0A'}"
32+
changelog="${changelog//$'\r'/'%0D'}"
33+
echo "::set-output name=changelog::$changelog"
34+
- name: echo version and changelog
35+
run: |
36+
echo "${{ steps.version.outputs.version}}"
37+
echo "${{ steps.changelog.outputs.changelog }}"
38+
- name: Create Release
39+
uses: ncipollo/[email protected]
40+
with:
41+
name: ${{ steps.version.outputs.version }}
42+
tag: v${{ steps.version.outputs.version }}
43+
body: ${{ steps.changelog.outputs.changelog}}
44+
draft: false
45+
prerelease: false
46+
# An optional tag for the release. If this is omitted the git ref will be used (if it is a tag).
47+
token: ${{ secrets.GITHUB_TOKEN }}
48+
49+
build-and-push-docker-image:
50+
needs: github-release
51+
runs-on: ubuntu-latest
52+
env:
53+
IMAGE_NAME: ${{github.repository}}
54+
permissions:
55+
contents: read
56+
packages: write
57+
58+
steps:
59+
- name: Checkout repository
60+
uses: actions/checkout@v2
61+
62+
- name: Set up Docker Buildx
63+
uses: docker/setup-buildx-action@v1
64+
65+
- name: Cache Docker layers
66+
uses: actions/cache@v2
67+
with:
68+
path: /tmp/.buildx-cache
69+
key: ${{ runner.os }}-buildx-${{ github.sha }}
70+
restore-keys: |
71+
${{ runner.os }}-buildx-
72+
- name: Login to DockerHub
73+
uses: docker/login-action@v1
74+
with:
75+
username: ${{ secrets.DOCKERHUB_USERNAME }}
76+
password: ${{ secrets.DOCKERHUB_TOKEN }}
77+
78+
- name: Log in to the Container registry
79+
uses: docker/[email protected]
80+
with:
81+
registry: ghcr.io
82+
username: ${{ github.actor }}
83+
password: ${{ secrets.GITHUB_TOKEN }}
84+
85+
- name: Extract metadata (tags, labels) for Docker
86+
id: meta
87+
uses: docker/[email protected]
88+
with:
89+
images: ${{ env.IMAGE_NAME }},ghcr.io/${{ env.IMAGE_NAME }}
90+
tags: |
91+
type=semver,pattern={{version}},value=${{needs.github-release.outputs.version}}
92+
- name: Build and push Docker image
93+
uses: docker/[email protected]
94+
with:
95+
context: .
96+
push: true
97+
tags: ${{ steps.meta.outputs.tags }}
98+
labels: ${{ steps.meta.outputs.labels }}
99+
cache-from: type=local,src=/tmp/.buildx-cache
100+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
101+
102+
- # Temp fix
103+
# https://github.com/docker/build-push-action/issues/252
104+
# https://github.com/moby/buildkit/issues/1896
105+
name: Move cache
106+
run: |
107+
rm -rf /tmp/.buildx-cache
108+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

.github/workflows/changelog.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Stolen from https://github.com/mrchief/aws-creds-okta-action/blob/master/.github/workflows/changelog.yml
2+
name: Auto Changelog
3+
4+
on:
5+
push:
6+
branches:
7+
- master
8+
- 'releases/**'
9+
10+
jobs:
11+
push:
12+
name: Push Container
13+
runs-on: ubuntu-latest
14+
if: "!contains(github.event.head_commit.message, 'ci: Release')"
15+
steps:
16+
- name: Checkout Code
17+
uses: actions/checkout@v2
18+
with:
19+
fetch-depth: '0'
20+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
21+
- name: autochangelog-action
22+
id: ac
23+
uses: rubenfiszel/[email protected]
24+
with:
25+
changelog_file: './CHANGELOG.md'
26+
manifest_file: './manifest.yml'
27+
dry_run: false
28+
issues_url_prefix: 'https://github.com/${{ github.repository }}/issues'
29+
tag_prefix: 'v'
30+
- name: Create Pull Request
31+
id: cpr
32+
uses: peter-evans/[email protected]
33+
with:
34+
token: ${{ secrets.GITHUB_TOKEN }}
35+
commit-message: 'Update changelog and manifest'
36+
title: 'ci: Release ${{ steps.ac.outputs.version }}'
37+
body: |
38+
Release v${{ steps.ac.outputs.version }}
39+
labels: autorelease
40+
branch: automatic-release-prs
41+
- name: Check outputs
42+
run: |
43+
echo "Pull Request Number - ${{ env.PULL_REQUEST_NUMBER }}"
44+
echo "Pull Request Number - ${{ steps.cpr.outputs.pr_number }}"

CHANGELOG.md

Whitespace-only changes.

manifest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version: 2.1.1

0 commit comments

Comments
 (0)