Skip to content

Commit a41aa82

Browse files
authored
Update release.yml
Swap out patched together workflow with official version provided by Github. This is cleaner, less likely to need maintenance later. Performs exactly the same job as previous.
1 parent d0fdb70 commit a41aa82

1 file changed

Lines changed: 45 additions & 49 deletions

File tree

.github/workflows/release.yml

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,56 @@
1-
name: Build release
1+
name: Create Release
22

3-
on:
3+
on:
44
push:
5-
branches: [ main ]
6-
# Publish semver tags as releases.
7-
tags: [ 'v*.*.*' ]
5+
6+
# Publish `master` as Docker `latest` image.
7+
branches:
8+
- main
9+
10+
# Publish `v1.2.3` tags as releases.
11+
tags:
12+
- v*
13+
14+
# Run for any PRs.
815
pull_request:
9-
branches: [ main ]
1016

17+
# Create a button to trigger the workflow manually.
1118
workflow_dispatch:
12-
branches: [ main ]
13-
tags: [ 'v*.*.*' ]
1419

1520
env:
16-
REGISTRY: ghcr.io
17-
# github.repository as <account>/<repo>
18-
IMAGE_NAME: ${{ github.repository }}
21+
# the target name of the image.
22+
IMAGE_NAME: deploy-from-github
1923

2024
jobs:
21-
buildx:
25+
# Push image to GitHub Packages Container Registry.
26+
push:
2227
runs-on: ubuntu-latest
23-
steps:
24-
-
25-
name: Checkout
26-
uses: actions/checkout@v3
27-
-
28-
name: Set up Docker Buildx
29-
id: buildx
30-
uses: docker/setup-buildx-action@v2
31-
32-
# Login against a Docker registry except on PR
33-
# https://github.com/docker/login-action
34-
- name: Log into registry ${{ env.REGISTRY }}
35-
if: github.event_name != 'pull_request'
36-
uses: docker/login-action@v2
37-
with:
38-
registry: ${{ env.REGISTRY }}
39-
username: ${{ github.actor }}
40-
password: ${{ secrets.GITHUB_TOKEN }}
41-
42-
# Extract metadata (tags, labels) for Docker
43-
# https://github.com/docker/metadata-action
44-
- name: Extract Docker metadata
45-
id: meta
46-
uses: docker/metadata-action@v4
47-
with:
48-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
49-
50-
# Build and push Docker image with Buildx (don't push on PR)
51-
# https://github.com/docker/build-push-action
52-
- name: Build and push Docker image
53-
id: build-and-push
54-
uses: docker/build-push-action@v3
55-
with:
56-
context: .
57-
push: ${{ github.event_name != 'pull_request' }}
58-
tags: ${{ steps.meta.outputs.tags }}
59-
labels: ${{ steps.meta.outputs.labels }}
28+
permissions:
29+
packages: write
30+
contents: read
6031

32+
steps:
33+
- uses: actions/checkout@v3
34+
35+
- name: Build image
36+
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
37+
38+
- name: Log in to registry
39+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
40+
41+
- name: Push image
42+
run: |
43+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
44+
45+
# Change all uppercase to lowercase
46+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
47+
# Strip git ref prefix from version
48+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
49+
# Strip "v" prefix from tag name
50+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
51+
# Use Docker `latest` tag convention
52+
[ "$VERSION" == "master" ] && VERSION=latest
53+
echo IMAGE_ID=$IMAGE_ID
54+
echo VERSION=$VERSION
55+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
56+
docker push $IMAGE_ID:$VERSION

0 commit comments

Comments
 (0)