Skip to content

Commit 0daba3f

Browse files
committed
Split build and release workflows
1 parent a34c682 commit 0daba3f

2 files changed

Lines changed: 74 additions & 41 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
name: Build
2-
on: [ push, pull_request, release, workflow_dispatch ]
2+
on: [ push, pull_request, workflow_dispatch ]
33
env:
44
REGISTRY: ghcr.io
5+
56
jobs:
7+
# TODO: DRY w/release.yml
68
setup:
79
runs-on: ubuntu-latest
810

@@ -62,7 +64,7 @@ jobs:
6264
runs-on: ubuntu-latest
6365

6466
container:
65-
image: ${{ needs.build.outputs.build_image }}
67+
image: ${{ needs.build.outputs.build_image }}
6668

6769
defaults:
6870
run:
@@ -91,7 +93,7 @@ jobs:
9193
name: artifacts
9294
path: /opt/app/artifacts/**
9395

94-
# TODO: DRY push and push-release
96+
# TODO: DRY w/release.yml
9597
push:
9698
if: github.event_name != 'release'
9799

@@ -126,41 +128,3 @@ jobs:
126128
dst: |
127129
${{ steps.meta.outputs.tags }}
128130
129-
# TODO: DRY push and push-release
130-
push-release:
131-
if: github.event_name == 'release' && github.event.action == 'published'
132-
133-
needs: [setup]
134-
env:
135-
BASE_IMAGE_NAME: ${{ needs.setup.outputs.base_image_name }}
136-
BUILD_IMAGE: ${{ needs.setup.outputs.build_image }}
137-
138-
runs-on: ubuntu-latest
139-
140-
permissions:
141-
packages: write
142-
143-
steps:
144-
- name: Extract metadata (tags, labels) for Docker
145-
id: meta
146-
uses: docker/metadata-action@v3
147-
with:
148-
images: ${{ env.BASE_IMAGE_NAME }}
149-
tags:
150-
type=semver,pattern={{major}}
151-
type=semver,pattern={{major}}.{{minor}}
152-
type=semver,pattern={{version}}
153-
154-
- name: Log in to the Container registry
155-
uses: docker/login-action@v2
156-
with:
157-
registry: ${{ env.REGISTRY }}
158-
username: ${{ github.actor }}
159-
password: ${{ secrets.GITHUB_TOKEN }}
160-
161-
- name: Tag and push image
162-
uses: akhilerm/tag-push-action@v2.0.0
163-
with:
164-
src: ${{ env.BUILD_IMAGE }}
165-
dst: |
166-
${{ steps.meta.outputs.tags }}

.github/workflows/release.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
workflow_dispatch:
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
12+
jobs:
13+
# TODO: DRY w/build.yml
14+
setup:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
# See https://github.com/docker/build-push-action/blob/v2.10.0/TROUBLESHOOTING.md#repository-name-must-be-lowercase
19+
- name: Sanitize image name
20+
uses: actions/github-script@v6
21+
id: image-name
22+
with:
23+
result-encoding: string
24+
script: return '${{ env.REGISTRY }}/${{ github.repository }}'.toLowerCase()
25+
26+
- name: Get short SHA
27+
run: |
28+
echo SHORT_SHA="${GITHUB_SHA:0:7}" >> $GITHUB_ENV
29+
30+
outputs:
31+
base_image_name: ${{ steps.image-name.outputs.result }}
32+
build_image: ${{ steps.image-name.outputs.result }}:${{ env.SHORT_SHA }}
33+
34+
# TODO: DRY w/build.yml
35+
push-release:
36+
needs: setup
37+
env:
38+
BASE_IMAGE_NAME: ${{ needs.setup.outputs.base_image_name }}
39+
BUILD_IMAGE: ${{ needs.setup.outputs.build_image }}
40+
41+
runs-on: ubuntu-latest
42+
43+
permissions:
44+
packages: write
45+
46+
steps:
47+
- name: Extract metadata (tags, labels) for Docker
48+
id: meta
49+
uses: docker/metadata-action@v3
50+
with:
51+
images: ${{ env.BASE_IMAGE_NAME }}
52+
tags:
53+
type=semver,pattern={{major}}
54+
type=semver,pattern={{major}}.{{minor}}
55+
type=semver,pattern={{version}}
56+
57+
- name: Log in to the Container registry
58+
uses: docker/login-action@v2
59+
with:
60+
registry: ${{ env.REGISTRY }}
61+
username: ${{ github.actor }}
62+
password: ${{ secrets.GITHUB_TOKEN }}
63+
64+
- name: Tag and push image
65+
uses: akhilerm/tag-push-action@v2.0.0
66+
with:
67+
src: ${{ env.BUILD_IMAGE }}
68+
dst: |
69+
${{ steps.meta.outputs.tags }}

0 commit comments

Comments
 (0)