Skip to content

Commit cd2c562

Browse files
authored
Enhance workflow conditionals for forked repositories and notifications (#4179)
1 parent 0a445cd commit cd2c562

4 files changed

Lines changed: 20 additions & 11 deletions

File tree

.github/workflows/build.yml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,13 @@ jobs:
102102
# Pin version for Java 8, also be sure to set in verify-pr.yml
103103
mcHelperVersion: 1.51.3-java8
104104
env:
105+
# Assume they line up, but when forked change to your Docker Hub username
106+
DOCKER_HUB_ORG: ${{ github.repository_owner }}
105107
IMAGE_TO_TEST: "${{ github.repository_owner }}/minecraft-server:test-${{ matrix.variant }}-${{ github.run_id }}"
106108
HAS_IMAGE_REPO_ACCESS: ${{ secrets.DOCKER_USER != '' && secrets.DOCKER_PASSWORD != '' }}
107109
MAIN_VARIANT: java25
110+
PUSH: ${{ github.repository_owner == 'itzg' }}
111+
IMAGE_AUTHOR: "Geoff Bourne <itzgeoff@gmail.com>"
108112
runs-on: ubuntu-22.04
109113
steps:
110114
- name: Checkout
@@ -117,10 +121,8 @@ jobs:
117121
id: meta
118122
uses: docker/metadata-action@v6.2.0
119123
with:
120-
# NOTE for forks: if your Docker Hub organization doesn't match your Github repo's,
121-
# then the use of ${{ github.repository_owner }} will need to be replaced.
122124
images: |
123-
${{ github.repository_owner }}/minecraft-server
125+
${{ env.DOCKER_HUB_ORG }}/minecraft-server
124126
ghcr.io/${{ github.repository_owner }}/minecraft-server
125127
tags: |
126128
# Apply the variant as a moving tag for most recent commit per variant
@@ -142,7 +144,7 @@ jobs:
142144
flavor: |
143145
latest=${{ matrix.variant == env.MAIN_VARIANT && github.ref_name == github.event.repository.default_branch }}
144146
labels: |
145-
org.opencontainers.image.authors=Geoff Bourne <itzgeoff@gmail.com>
147+
org.opencontainers.image.authors=${{ env.IMAGE_AUTHOR }}
146148
147149
- name: Setup Docker Buildx
148150
uses: docker/setup-buildx-action@v4
@@ -198,13 +200,16 @@ jobs:
198200
platforms: ${{ matrix.platforms }}
199201
push: >
200202
${{
201-
github.ref_type == 'tag'
202-
|| github.ref_name == github.event.repository.default_branch
203-
|| startsWith(github.ref_name, 'test/')
204-
|| ( github.event_name == 'pull_request'
205-
&& env.HAS_IMAGE_REPO_ACCESS
206-
&& contains(github.event.pull_request.labels.*.name, 'ci/push-image')
207-
)
203+
env.PUSH &&
204+
(
205+
github.ref_type == 'tag'
206+
|| github.ref_name == github.event.repository.default_branch
207+
|| startsWith(github.ref_name, 'test/')
208+
|| ( github.event_name == 'pull_request'
209+
&& env.HAS_IMAGE_REPO_ACCESS
210+
&& contains(github.event.pull_request.labels.*.name, 'ci/push-image')
211+
)
212+
)
208213
}}
209214
tags: ${{ steps.meta.outputs.tags }}
210215
# ensure latest base image is used
@@ -221,5 +226,6 @@ jobs:
221226
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
222227
${{ matrix.mcHelperVersion && format('MC_HELPER_VERSION={0}', matrix.mcHelperVersion) }}
223228
${{ matrix.knockdRepoOrg && format('KNOCKD_REPO_ORG={0}', matrix.knockdRepoOrg) }}
229+
IMAGE_AUTHOR=${{ env.IMAGE_AUTHOR }}
224230
cache-from: type=gha,scope=${{ matrix.variant }}
225231
cache-to: type=gha,mode=max,scope=${{ matrix.variant }}

.github/workflows/discord.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
discord:
1717
runs-on: ubuntu-latest
1818
timeout-minutes: 5
19+
if: github.repository_owner == 'itzg'
1920
steps:
2021
- name: on-publish
2122
if: github.event_name == 'release' && github.event.action == 'published'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313
- labeled
1414
jobs:
1515
notify:
16+
if: github.repository_owner == 'itzg'
1617
uses: itzg/github-workflows/.github/workflows/issues-notify-discord.yml@main
1718
with:
1819
triageLabel: 'status/needs triage'

.github/workflows/stale-check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
jobs:
88
check:
99
runs-on: ubuntu-22.04
10+
if: github.repository_owner == 'itzg'
1011
permissions:
1112
issues: write
1213
pull-requests: write

0 commit comments

Comments
 (0)