Skip to content

Commit f855c38

Browse files
committed
ci: restrict workflows to run only on main repo
Prevent workflows from running on forks by adding repository owner checks to workflows that publish artifacts or use self-hosted runners. - Add check to `push.yaml` to prevent image publishing on forks - Add check to `release.yaml` to prevent release creation on forks - Add check to `k8s-bm.yaml` to prevent self-hosted runner usage on forks - Add check to `profiling.yaml` to prevent self-hosted runner usage on forks - Removed `Extract version` step from `release.yaml` since it is redundant and just copying `github.ref_name` to a step variable output without any transformation or processing This ensures fork contributors don't need to manually disable workflows and prevents unnecessary runs on forks. Signed-off-by: vprashar2929 <[email protected]>
1 parent 826b223 commit f855c38

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

.github/workflows/k8s-bm.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
3131
build-and-deploy:
3232
needs: [check-changes]
33-
if: needs.check-changes.outputs.changes == 'true'
33+
if: needs.check-changes.outputs.changes == 'true' && github.repository_owner == 'sustainable-computing-io'
3434
runs-on: self-hosted
3535
steps:
3636
# NOTE: In case of self-hosted runners, tools like docker, make, kubectl etc. are installed at the time of setting up the runner.

.github/workflows/profiling.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
2929
profiling:
3030
needs: check-changes
31-
if: needs.check-changes.outputs.changes == 'true'
31+
if: needs.check-changes.outputs.changes == 'true' && github.repository_owner == 'sustainable-computing-io'
3232
runs-on: self-hosted
3333
steps:
3434
# NOTE: In case of self-hosted runners, tools like docker, make, kubectl etc. are installed at the time of setting up the runner.

.github/workflows/push.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
uses: ./.github/workflows/scorecard.yml
2424

2525
publish:
26+
if: github.repository_owner == 'sustainable-computing-io'
2627
runs-on: ubuntu-latest
2728
steps:
2829
- name: Checkout source

.github/workflows/release.yaml

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ on: # yamllint disable-line rule:truthy
77

88
# default permissions as read only
99
permissions: read-all
10-
1110
jobs:
1211
build:
12+
if: github.repository_owner == 'sustainable-computing-io'
1313
runs-on: ubuntu-latest
1414
env:
1515
IMG_BASE: quay.io/sustainable_computing_io
@@ -45,22 +45,15 @@ jobs:
4545
shell: bash
4646
run: make deps
4747

48-
- name: Extract version
49-
shell: bash
50-
id: version
51-
run: |
52-
TAG_NAME=${{ github.ref_name }}
53-
echo "version=$TAG_NAME" >> "$GITHUB_OUTPUT"
54-
5548
- name: Build Image
5649
shell: bash
5750
run: |
58-
make image VERSION=${{ steps.version.outputs.version }}
51+
make image VERSION=${{ github.ref_name }}
5952
6053
- name: Update Helm Chart Version
6154
shell: bash
6255
run: |
63-
VERSION=${{ steps.version.outputs.version }}
56+
VERSION=${{ github.ref_name }}
6457
# Remove 'v' prefix from version
6558
CHART_VERSION=${VERSION#v}
6659
# Update Chart.yaml with the release version
@@ -71,7 +64,7 @@ jobs:
7164
shell: bash
7265
run: |
7366
mkdir -p helm-releases
74-
VERSION=${{ steps.version.outputs.version }}
67+
VERSION=${{ github.ref_name }}
7568
# Remove 'v' prefix from version
7669
CHART_VERSION=${VERSION#v}
7770
helm package manifests/helm/kepler -d helm-releases
@@ -81,7 +74,7 @@ jobs:
8174
- name: Build Kepler binary
8275
shell: bash
8376
run: |
84-
VERSION=${{ steps.version.outputs.version }}
77+
VERSION=${{ github.ref_name }}
8578
# Remove 'v' prefix from version
8679
VERSION=${VERSION#v}
8780
make build PRODUCTION=1
@@ -101,12 +94,12 @@ jobs:
10194
- name: Push Image
10295
shell: bash
10396
run: |
104-
make push VERSION=${{ steps.version.outputs.version }}
97+
make push VERSION=${{ github.ref_name }}
10598
10699
- name: Push Helm Chart to OCI registry
107100
shell: bash
108101
run: |
109-
VERSION=${{ steps.version.outputs.version }}
102+
VERSION=${{ github.ref_name }}
110103
# Remove 'v' prefix from version
111104
CHART_VERSION=${VERSION#v}
112105
helm push helm-releases/kepler-helm-${CHART_VERSION}.tgz oci://${{ env.IMG_BASE }}/charts
@@ -125,18 +118,11 @@ jobs:
125118
with:
126119
name: release-artifacts
127120

128-
- name: Extract version
129-
shell: bash
130-
id: version
131-
run: |
132-
TAG_NAME=${{ github.ref_name }}
133-
echo "version=$TAG_NAME" >> "$GITHUB_OUTPUT"
134-
135121
- name: Create GitHub Release
136122
uses: softprops/action-gh-release@v2
137123
with:
138124
tag_name: ${{ github.ref_name }}
139-
name: release-${{ steps.version.outputs.version }}
125+
name: release-${{ github.ref_name }}
140126
generate_release_notes: true
141127
draft: false
142128
make_latest: true

0 commit comments

Comments
 (0)