Skip to content

Commit a9153de

Browse files
committed
[PM-15127] Remove secrets requirement from build workflow
1 parent d345937 commit a9153de

File tree

3 files changed

+53
-22
lines changed

3 files changed

+53
-22
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ src/Admin/Views/Tools @bitwarden/team-billing-dev
6666

6767
# Platform team
6868
.github/workflows/build.yml @bitwarden/team-platform-dev
69+
.github/workflows/build_target.yml @bitwarden/team-platform-dev
6970
.github/workflows/cleanup-after-pr.yml @bitwarden/team-platform-dev
7071
.github/workflows/cleanup-rc-branch.yml @bitwarden/team-platform-dev
7172
.github/workflows/repository-management.yml @bitwarden/team-platform-dev

.github/workflows/build.yml

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@ on:
77
- "main"
88
- "rc"
99
- "hotfix-rc"
10-
pull_request_target:
10+
pull_request:
1111
types: [opened, synchronize]
12+
workflow_call:
13+
inputs: {}
1214

1315
env:
1416
_AZ_REGISTRY: "bitwardenprod.azurecr.io"
1517

1618
jobs:
17-
check-run:
18-
name: Check PR run
19-
uses: bitwarden/gh-actions/.github/workflows/check-run.yml@main
20-
2119
lint:
2220
name: Lint
2321
runs-on: ubuntu-22.04
24-
needs:
25-
- check-run
2622
steps:
2723
- name: Check out repo
2824
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -40,6 +36,8 @@ jobs:
4036
runs-on: ubuntu-22.04
4137
needs:
4238
- lint
39+
outputs:
40+
has_secrets: ${{ steps.check-secrets.outputs.has_secrets }}
4341
strategy:
4442
fail-fast: false
4543
matrix:
@@ -75,6 +73,14 @@ jobs:
7573
base_path: ./bitwarden_license/src
7674
node: true
7775
steps:
76+
- name: Check secrets
77+
id: check-secrets
78+
env:
79+
AZURE_KV_CI_SERVICE_PRINCIPAL: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}
80+
run: |
81+
has_secrets=${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL != '' }}
82+
echo "has_secrets=$has_secrets" >> $GITHUB_OUTPUT
83+
7884
- name: Check out repo
7985
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
8086
with:
@@ -134,6 +140,7 @@ jobs:
134140
id-token: write
135141
needs:
136142
- build-artifacts
143+
if: ${{ needs.build-artifacts.outputs.has_secrets == 'true' }}
137144
strategy:
138145
fail-fast: false
139146
matrix:
@@ -227,7 +234,7 @@ jobs:
227234
- name: Generate Docker image tag
228235
id: tag
229236
run: |
230-
if [[ "${GITHUB_EVENT_NAME}" == "pull_request_target" ]]; then
237+
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
231238
IMAGE_TAG=$(echo "${GITHUB_HEAD_REF}" | sed "s#/#-#g")
232239
else
233240
IMAGE_TAG=$(echo "${GITHUB_REF:11}" | sed "s#/#-#g")
@@ -289,11 +296,11 @@ jobs:
289296
"GH_PAT=${{ steps.retrieve-secret-pat.outputs.github-pat-bitwarden-devops-bot-repo-scope }}"
290297
291298
- name: Install Cosign
292-
if: github.event_name != 'pull_request_target' && github.ref == 'refs/heads/main'
299+
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
293300
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0
294301

295302
- name: Sign image with Cosign
296-
if: github.event_name != 'pull_request_target' && github.ref == 'refs/heads/main'
303+
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
297304
env:
298305
DIGEST: ${{ steps.build-docker.outputs.digest }}
299306
TAGS: ${{ steps.image-tags.outputs.tags }}
@@ -322,6 +329,7 @@ jobs:
322329
name: Upload
323330
runs-on: ubuntu-22.04
324331
needs: build-docker
332+
if: ${{ needs.build-artifacts.outputs.has_secrets == 'true' }}
325333
steps:
326334
- name: Check out repo
327335
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -341,7 +349,7 @@ jobs:
341349

342350
- name: Make Docker stubs
343351
if: |
344-
github.event_name != 'pull_request_target'
352+
github.event_name != 'pull_request'
345353
&& (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc')
346354
run: |
347355
# Set proper setup image based on branch
@@ -383,15 +391,15 @@ jobs:
383391
384392
- name: Make Docker stub checksums
385393
if: |
386-
github.event_name != 'pull_request_target'
394+
github.event_name != 'pull_request'
387395
&& (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc')
388396
run: |
389397
sha256sum docker-stub-US.zip > docker-stub-US-sha256.txt
390398
sha256sum docker-stub-EU.zip > docker-stub-EU-sha256.txt
391399
392400
- name: Upload Docker stub US artifact
393401
if: |
394-
github.event_name != 'pull_request_target'
402+
github.event_name != 'pull_request'
395403
&& (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc')
396404
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
397405
with:
@@ -401,7 +409,7 @@ jobs:
401409

402410
- name: Upload Docker stub EU artifact
403411
if: |
404-
github.event_name != 'pull_request_target'
412+
github.event_name != 'pull_request'
405413
&& (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc')
406414
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
407415
with:
@@ -411,7 +419,7 @@ jobs:
411419

412420
- name: Upload Docker stub US checksum artifact
413421
if: |
414-
github.event_name != 'pull_request_target'
422+
github.event_name != 'pull_request'
415423
&& (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc')
416424
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
417425
with:
@@ -421,7 +429,7 @@ jobs:
421429

422430
- name: Upload Docker stub EU checksum artifact
423431
if: |
424-
github.event_name != 'pull_request_target'
432+
github.event_name != 'pull_request'
425433
&& (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc')
426434
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
427435
with:
@@ -550,7 +558,7 @@ jobs:
550558
self-host-build:
551559
name: Trigger self-host build
552560
if: |
553-
github.event_name != 'pull_request_target'
561+
github.event_name != 'pull_request'
554562
&& (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc')
555563
runs-on: ubuntu-22.04
556564
needs:
@@ -585,7 +593,7 @@ jobs:
585593
586594
trigger-k8s-deploy:
587595
name: Trigger k8s deploy
588-
if: github.event_name != 'pull_request_target' && github.ref == 'refs/heads/main'
596+
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
589597
runs-on: ubuntu-22.04
590598
needs:
591599
- build-docker
@@ -621,7 +629,8 @@ jobs:
621629
trigger-ee-updates:
622630
name: Trigger Ephemeral Environment updates
623631
if: |
624-
github.event_name == 'pull_request_target'
632+
needs.build-artifacts.outputs.has_secrets == 'true'
633+
&& github.event_name == 'pull_request'
625634
&& contains(github.event.pull_request.labels.*.name, 'ephemeral-environment')
626635
runs-on: ubuntu-24.04
627636
needs:
@@ -658,7 +667,8 @@ jobs:
658667
name: Trigger Ephemeral Environment Sync
659668
needs: trigger-ee-updates
660669
if: |
661-
github.event_name == 'pull_request_target'
670+
needs.build-artifacts.outputs.has_secrets == 'true'
671+
&& github.event_name == 'pull_request'
662672
&& contains(github.event.pull_request.labels.*.name, 'ephemeral-environment')
663673
uses: bitwarden/gh-actions/.github/workflows/_ephemeral_environment_manager.yml@main
664674
with:
@@ -668,7 +678,6 @@ jobs:
668678
pull_request_number: ${{ github.event.number }}
669679
secrets: inherit
670680

671-
672681
check-failures:
673682
name: Check for failures
674683
if: always()
@@ -684,7 +693,7 @@ jobs:
684693
steps:
685694
- name: Check if any job failed
686695
if: |
687-
github.event_name != 'pull_request_target'
696+
github.event_name != 'pull_request'
688697
&& (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc')
689698
&& contains(needs.*.result, 'failure')
690699
run: exit 1

.github/workflows/build_target.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build on PR Target
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
defaults:
8+
run:
9+
shell: bash
10+
11+
jobs:
12+
check-run:
13+
name: Check PR run
14+
uses: bitwarden/gh-actions/.github/workflows/check-run.yml@main
15+
16+
run-workflow:
17+
name: Run Build on PR Target
18+
needs: check-run
19+
if: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
20+
uses: ./.github/workflows/build.yml
21+
secrets: inherit

0 commit comments

Comments
 (0)