Skip to content

Commit 05bf187

Browse files
Add branch protection to the test image build pipeline (#15)
This adds branch protection to the workflow for building container test images. This PR additionally moves the permissions for docs deploying to be job level. Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
1 parent e81df1c commit 05bf187

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

.github/workflows/build-test-images.yml

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,37 @@ jobs:
3232
contents: read
3333
packages: write
3434
steps:
35-
- name: Check inputs
36-
run: |
37-
if [ ${{ inputs.image }} == 'dockermanifestimage' ] && [ ${{ inputs.useBuildx }} == true ]; then
38-
echo "dockermanifestimage cannot be built with buildx"
39-
exit 1
40-
fi
35+
- name: Check branch
36+
run: |
37+
if [ '${{ github.ref }}' != 'refs/heads/main' ] && [[ '${{ github.ref }}' != 'refs/heads/release*' ]] && [ ${{ inputs.publish }} == true ]; then
38+
echo "Cannot publish an image if we are not on main or a release branch."
39+
exit 1
40+
fi
41+
- name: Check inputs
42+
run: |
43+
if [ ${{ inputs.image }} == 'dockermanifestimage' ] && [ ${{ inputs.useBuildx }} == true ]; then
44+
echo "dockermanifestimage cannot be built with buildx"
45+
exit 1
46+
fi
4147
42-
if [ ${{ inputs.image }} == 'emptyimage' ] && [ ${{ inputs.useBuildx}} != true ]; then
43-
echo "emptyimage should be built with buildx"
44-
exit 1
45-
fi
46-
- name: Checkout repository
47-
uses: actions/checkout@v4
48-
- name: Login to GitHub Container Registry
49-
uses: docker/login-action@v3
50-
with:
51-
registry: ghcr.io
52-
username: ${{ github.actor }}
53-
password: ${{ secrets.GITHUB_TOKEN }}
54-
- name: Set up Docker Buildx
55-
if: ${{ inputs.useBuildx }}
56-
uses: docker/setup-buildx-action@v3
57-
- name: Build dockerfile and push image
58-
uses: docker/build-push-action@v6
59-
with:
60-
push: ${{ inputs.publish }}
61-
context: Tests/TestImages/${{ inputs.image }}
62-
tags: ghcr.io/apple/containerization/${{ inputs.image }}:${{ inputs.version }}
48+
if [ ${{ inputs.image }} == 'emptyimage' ] && [ ${{ inputs.useBuildx}} != true ]; then
49+
echo "emptyimage should be built with buildx"
50+
exit 1
51+
fi
52+
- name: Checkout repository
53+
uses: actions/checkout@v4
54+
- name: Login to GitHub Container Registry
55+
uses: docker/login-action@v3
56+
with:
57+
registry: ghcr.io
58+
username: ${{ github.actor }}
59+
password: ${{ secrets.GITHUB_TOKEN }}
60+
- name: Set up Docker Buildx
61+
if: ${{ inputs.useBuildx }}
62+
uses: docker/setup-buildx-action@v3
63+
- name: Build dockerfile and push image
64+
uses: docker/build-push-action@v6
65+
with:
66+
push: ${{ inputs.publish }}
67+
context: Tests/TestImages/${{ inputs.image }}
68+
tags: ghcr.io/apple/containerization/${{ inputs.image }}:${{ inputs.version }}

.github/workflows/docs-release.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ name: Deploy application website
44
on:
55
workflow_dispatch:
66

7-
permissions:
8-
contents: read
9-
packages: write
10-
pages: write
11-
127
jobs:
138
checkBranch:
149
runs-on: ubuntu-latest
15-
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'ref/heads/release')
10+
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release')
1611
steps:
1712
- name: Branch validation
1813
run: echo "Branch ${{ github.ref_name }} is allowed"
@@ -22,10 +17,18 @@ jobs:
2217
needs: checkBranch
2318
uses: ./.github/workflows/containerization-build-template.yml
2419
secrets: inherit
20+
permissions:
21+
contents: read
22+
packages: write
23+
pages: write
2524

2625
deployDocs:
2726
runs-on: ubuntu-latest
2827
needs: [checkBranch, buildSite]
28+
permissions:
29+
contents: read
30+
packages: write
31+
pages: write
2932

3033
environment:
3134
name: github-pages

0 commit comments

Comments
 (0)