Skip to content

Commit 40750bc

Browse files
committed
BUILD/MAJOR: add autobuild script
1 parent 7d72e84 commit 40750bc

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: ghcr.io image
2+
3+
on:
4+
push:
5+
# Publish `main` as Docker `latest` image.
6+
branches:
7+
- main
8+
9+
# Publish `v1.2.3` tags as releases.
10+
tags:
11+
- v*
12+
13+
env:
14+
IMAGE_NAME: commit-check
15+
16+
jobs:
17+
# Push image to GitHub Packages.
18+
# See also https://docs.docker.com/docker-hub/builds/
19+
push:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
packages: write
23+
contents: read
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
28+
- name: Build image
29+
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
30+
31+
- name: Log in to registry
32+
# This is where you will update the PAT to GITHUB_TOKEN
33+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
34+
35+
- name: Push image
36+
run: |
37+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
38+
39+
# Change all uppercase to lowercase
40+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
41+
# Strip git ref prefix from version
42+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
43+
# Strip "v" prefix from tag name
44+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
45+
# Use Docker `latest` tag convention
46+
[ "$VERSION" == "main" ] && VERSION=latest
47+
echo IMAGE_ID=$IMAGE_ID
48+
echo VERSION=$VERSION
49+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
50+
docker push $IMAGE_ID:$VERSION

0 commit comments

Comments
 (0)