Skip to content

Commit 3f31dac

Browse files
authored
ci: Improve ability to use CI in forks & fix multiple tag bug (#189)
* Add empty for debug * fix all runs-on to be dynamic * only read vault secrets when repo matches rancher/prom-fed * Install YQ only in GHA runners where YQ isn't available * Ensure package-helm uses the current tag for chart versioning * fix runs-on format to respect matrix.arch
1 parent e5ed3ff commit 3f31dac

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

.github/workflows/ci.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,25 @@ jobs:
3333
arch:
3434
- x64
3535
- arm64
36-
runs-on : runs-on,image=ubuntu22-full-${{ matrix.arch }},runner=4cpu-linux-${{ matrix.arch }},run-id=${{ github.run_id }}
36+
runs-on: ${{ github.repository == 'rancher/prometheus-federator' && format('runs-on,image=ubuntu22-full-{1},runner=4cpu-linux-{1},run-id={0}', github.run_id, matrix.arch) || 'ubuntu-latest' }}
3737
steps:
3838
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
3939
- name : Set up Go
4040
uses: actions/setup-go@bfdd3570ce990073878bf10f6b2d79082de49492 # v2
4141
with:
4242
go-version: '1.22'
43+
- name: Check if yq is installed
44+
id: check_yq
45+
run: |
46+
if ! command -v yq &> /dev/null; then
47+
echo "yq not found, installing..."
48+
echo "::set-output name=install_yq::true"
49+
else
50+
echo "yq is already installed"
51+
echo "::set-output name=install_yq::false"
52+
fi
4353
- name : Install YQ
54+
if: steps.check_yq.outputs.install_yq == 'true'
4455
run: |
4556
sudo wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${{ matrix.arch == 'x64' && 'amd64' || matrix.arch }} -O /usr/bin/yq && sudo chmod +x /usr/bin/yq;
4657
- name : Install helm

.github/workflows/integration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- v1.30.9-k3s1
3737
- v1.32.1-k3s1
3838
name : integration-test
39-
runs-on : runs-on,image=ubuntu22-full-${{ matrix.arch }},runner=4cpu-linux-${{ matrix.arch }},run-id=${{ github.run_id }}
39+
runs-on: ${{ github.repository == 'rancher/prometheus-federator' && format('runs-on,image=ubuntu22-full-{1},runner=4cpu-linux-{1},run-id={0}', github.run_id, matrix.arch) || 'ubuntu-latest' }}
4040
steps:
4141
- name : Checkout repository
4242
uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

.github/workflows/prom-fed-e2e-ci.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
arch:
5454
- x64
5555
- arm64
56-
runs-on : runs-on,image=ubuntu22-full-${{ matrix.arch }},runner=4cpu-linux-${{ matrix.arch }},run-id=${{ github.run_id }}
56+
runs-on: ${{ github.repository == 'rancher/prometheus-federator' && format('runs-on,image=ubuntu22-full-{1},runner=4cpu-linux-{1},run-id={0}', github.run_id, matrix.arch) || 'ubuntu-latest' }}
5757
steps:
5858
-
5959
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
@@ -67,8 +67,20 @@ jobs:
6767
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3
6868
with:
6969
token: ${{ secrets.GITHUB_TOKEN }}
70-
-
71-
name: Install mikefarah/yq
70+
- name: Check if yq is installed
71+
id: check_yq
72+
run: |
73+
if ! command -v yq &> /dev/null; then
74+
echo "yq not found, installing..."
75+
echo "::set-output name=install_yq::true"
76+
else
77+
echo "yq is already installed"
78+
YQ_BIN=$(which yq)
79+
echo "::set-output name=install_yq::false"
80+
echo "::set-output name=yq_path::$YQ_BIN"
81+
fi
82+
- name : Install YQ
83+
if: steps.check_yq.outputs.install_yq == 'true'
7284
run: |
7385
sudo wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${{ matrix.arch == 'x64' && 'amd64' || matrix.arch }} -O /usr/bin/yq && sudo chmod +x /usr/bin/yq;
7486
- name : Export image version

.github/workflows/publish.yaml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses : ./.github/workflows/prom-fed-e2e-ci.yaml
2121
goreleaser:
2222
name: Build go binaries and helm chart
23-
runs-on : runs-on,image=ubuntu22-full-x64,runner=4cpu-linux-x64,run-id=${{ github.run_id }}
23+
runs-on: ${{ github.repository == 'rancher/prometheus-federator' && format('runs-on,image=ubuntu22-full-x64,runner=4cpu-linux-x64,run-id={0}', github.run_id) || 'ubuntu-latest' }}
2424
needs: [
2525
ci,
2626
integration,
@@ -37,7 +37,18 @@ jobs:
3737
uses : actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5
3838
with:
3939
go-version: 1.22
40-
- name: Install mikefarah/yq
40+
- name: Check if yq is installed
41+
id: check_yq
42+
run: |
43+
if ! command -v yq &> /dev/null; then
44+
echo "yq not found, installing..."
45+
echo "::set-output name=install_yq::true"
46+
else
47+
echo "yq is already installed"
48+
echo "::set-output name=install_yq::false"
49+
fi
50+
- name : Install YQ
51+
if: steps.check_yq.outputs.install_yq == 'true'
4152
run: |
4253
sudo wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq;
4354
- uses: azure/setup-kubectl@901a10e89ea615cf61f57ac05cecdf23e7de06d8 # v3
@@ -47,7 +58,7 @@ jobs:
4758
token: ${{ secrets.GITHUB_TOKEN }}
4859
- name: Prepare helm charts (needed for build)
4960
run: |
50-
BUILD_TARGET=prometheus-federator make package-helm && echo "pf: release chart prepared"
61+
GIT_TAG=${{ github.ref_name }} BUILD_TARGET=prometheus-federator make package-helm && echo "pf: release chart prepared"
5162
BUILD_TARGET=prometheus-federator make build-chart && echo "pf: embedded project-monitoring chart prepared"
5263
- uses: goreleaser/goreleaser-action@90a3faa9d0182683851fbfa97ca1a2cb983bfca3 # v6
5364
with:
@@ -59,7 +70,7 @@ jobs:
5970
GORELEASER_CURRENT_TAG: ${{ github.ref_name }}
6071
push-dev-images:
6172
name : Build and push helm-locker & Helm-Project-Operator images
62-
runs-on : runs-on,image=ubuntu22-full-x64,runner=4cpu-linux-x64,run-id=${{ github.run_id }}
73+
runs-on: ${{ github.repository == 'rancher/prometheus-federator' && format('runs-on,image=ubuntu22-full-x64,runner=4cpu-linux-x64,run-id={0}', github.run_id) || 'ubuntu-latest' }}
6374
needs: [
6475
ci,
6576
integration,
@@ -98,6 +109,7 @@ jobs:
98109
publish-images:
99110
name: Publish prometheus-federator image
100111
runs-on: ubuntu-latest
112+
continue-on-error: true
101113
needs: [
102114
ci,
103115
integration,
@@ -107,8 +119,9 @@ jobs:
107119
contents : read
108120
id-token: write
109121
steps:
110-
- name : "Read Secrets"
111-
uses : rancher-eio/read-vault-secrets@main
122+
- name: "Read Secrets"
123+
if: github.repository == 'rancher/prometheus-federator'
124+
uses: rancher-eio/read-vault-secrets@main
112125
with:
113126
secrets: |
114127
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;

0 commit comments

Comments
 (0)