1+ name : KUCut-build
2+
3+ on :
4+ push :
5+ # Publish `v1.2.3` tags as releases.
6+ tags :
7+ - kucut-v*
8+
9+ # Run tests for any PRs.
10+ pull_request :
11+
12+ env :
13+ # TODO: Change variable to your image's name.
14+ IMAGE_NAME : kucut
15+
16+ jobs :
17+ # Run tests.
18+ # See also https://docs.docker.com/docker-hub/builds/automated-testing/
19+ test :
20+ runs-on : ubuntu-20.04
21+
22+ steps :
23+ - uses : actions/checkout@v2
24+
25+ - name : Run tests
26+ run : |
27+ cd kucut
28+ docker build . --file Dockerfile
29+ # Push image to GitHub Packages.
30+ # See also https://docs.docker.com/docker-hub/builds/
31+ push :
32+ # Ensure test job passes before pushing image.
33+ needs : test
34+
35+ runs-on : ubuntu-latest
36+ if : github.event_name == 'push'
37+
38+ steps :
39+ - uses : actions/checkout@v2
40+
41+ - name : Build image
42+ run : |
43+ cd kucut
44+ docker build . --file Dockerfile --tag $IMAGE_NAME
45+
46+ - name : Log into registry
47+ run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
48+
49+ - name : Push image
50+ run : |
51+ IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
52+
53+ # Change all uppercase to lowercase
54+ IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
55+ # Strip git ref prefix from version
56+ VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
57+ # Strip "v" prefix from tag name
58+ [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
59+ # Use Docker `latest` tag convention
60+ [ "$VERSION" == "main" ] && VERSION=latest
61+ echo IMAGE_ID=$IMAGE_ID
62+ echo VERSION=$VERSION
63+ docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
64+ docker push $IMAGE_ID:$VERSION
0 commit comments