Skip to content

Commit 051f92c

Browse files
authored
Build docker images from open PRs (zeusops#31)
1 parent 90f962b commit 051f92c

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

.github/workflows/ghcr.yaml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
---
22
name: Publish Docker
33

4+
# Allow publishing dev images from open PRs
5+
permissions:
6+
packages: write
7+
48
on:
59
push:
10+
branches:
11+
- main
12+
pull_request:
613

714
env:
8-
IMAGE_TAG: ghcr.io/${{ github.repository_owner }}/zeusops-bot:latest
15+
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/zeusops-bot
916

1017
jobs:
1118
build:
@@ -14,10 +21,10 @@ jobs:
1421
steps:
1522
- uses: actions/checkout@master
1623
- name: Login to GitHub Container Registry
17-
uses: docker/login-action@v1
24+
uses: docker/login-action@v3
1825
with:
1926
registry: ghcr.io
20-
username: ${{ github.repository_owner }}
27+
username: ${{ github.actor }}
2128
password: ${{ secrets.GITHUB_TOKEN }}
2229
- name: Build Image
2330
run: docker build -f release.Dockerfile -t zeusops-bot .
@@ -30,27 +37,31 @@ jobs:
3037
if-no-files-found: error
3138
retention-days: 7
3239

33-
main_publish:
40+
publish:
3441
name: Publish Image
3542
runs-on: ubuntu-latest
3643
needs:
3744
- build
38-
if: github.ref == 'refs/heads/main'
3945
steps:
46+
- name: Create Release Image Name
47+
if: github.ref == 'refs/heads/main'
48+
run: |
49+
echo "IMAGE_TAG_LOWER=${IMAGE_NAME@L}:latest" >> "${GITHUB_ENV}"
50+
- name: Create PR Image Name
51+
if: github.event_name == 'pull_request'
52+
run: |
53+
echo "IMAGE_TAG_LOWER=${IMAGE_NAME@L}:dev-pr-${{ github.event.number }}" >> "${GITHUB_ENV}"
4054
- name: Login to GHCR
41-
uses: docker/login-action@v1
55+
uses: docker/login-action@v3
4256
with:
4357
registry: ghcr.io
44-
username: ${{ github.repository_owner }}
58+
username: ${{ github.actor }}
4559
password: ${{ secrets.GITHUB_TOKEN }}
4660
- uses: actions/download-artifact@v4
4761
with:
4862
name: image
4963
- name: Load Image
5064
run: docker load < image.tar.gz
51-
- name: lowercase repo
52-
run: |
53-
echo "IMAGE_TAG_LOWER=${IMAGE_TAG@L}" >> "${GITHUB_ENV}"
5465
- name: Tag Image
5566
run: docker tag zeusops-bot "$IMAGE_TAG_LOWER"
5667
- name: Push Image

0 commit comments

Comments
 (0)