Skip to content

Commit 6944b9c

Browse files
committed
perf: configure branch name
1 parent cbea376 commit 6944b9c

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

.github/workflows/pi_build.yml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,35 @@ env:
1313
GH_TOKEN: ${{ secrets.GH_TOKEN }}
1414

1515
jobs:
16+
configure-branch-name:
17+
name: 'Configure Head Branch Name'
18+
runs-on: ubuntu-latest
19+
outputs:
20+
gh_head_ref: ${{ steps.configure-branch-name.outputs.gh_head_ref }}
21+
steps:
22+
- name: Configure branch name
23+
id: configure-branch-name
24+
run: echo "gh_head_ref=$(echo "${{ github.event.pull_request.head.ref }}" | sed 's|/|-|g')" >> $GITHUB_OUTPUT
25+
1626
pi-matrix:
1727
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/pi_matrix.yml@dev
1828
secrets: inherit
29+
needs: [configure-branch-name]
1930
with:
20-
checkout_ref: ${{ github.event.pull_request.head.ref }}
31+
checkout_ref: ${{ needs.configure-branch-name.outputs.gh_head_ref }}
2132
repository: "${{ github.repository_owner }}/refinery-submodule-parent-images"
2233

2334
pi-build:
2435
name: 'Parent Images: Docker Build'
2536
runs-on: ubuntu-latest
26-
needs: [pi-matrix]
37+
needs: [pi-matrix, configure-branch-name]
2738
environment: dev
2839
env:
2940
PYTHON_VERSION: ${{ vars.PYTHON_VERSION }}
3041
DEV_CONTAINER_REGISTRY: ${{ vars.DEV_CONTAINER_REGISTRY }}
3142
DEV_LOGIN_USERNAME: ${{ secrets.DEV_LOGIN_USERNAME }}
3243
DEV_LOGIN_PASSWORD: ${{ secrets.DEV_LOGIN_PASSWORD }}
33-
IMAGE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || github.event.pull_request.head.ref }}
44+
IMAGE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || needs.configure-branch-name.outputs.gh_head_ref }}
3445
strategy:
3546
matrix:
3647
parent_image_type: ${{ fromJson(needs.pi-matrix.outputs.parent_image_type) }}
@@ -54,7 +65,7 @@ jobs:
5465
- name: Compile Requirements
5566
run: |
5667
cd ${{ github.workspace }}/submodules/parent-images
57-
git checkout ${{ github.event.pull_request.head.ref }}
68+
git checkout ${{ needs.configure-branch-name.outputs.gh_head_ref }}
5869
pip-compile requirements/${{ matrix.parent_image_type }}-requirements.in
5970
6071
- name: Set up Docker Buildx
@@ -74,29 +85,29 @@ jobs:
7485
username: "${{ env.DEV_LOGIN_USERNAME }}"
7586
password: "${{ env.DEV_LOGIN_PASSWORD }}"
7687

77-
- name: Build & Push refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}
88+
- name: Build & Push refinery-parent-images:${{ needs.configure-branch-name.outputs.gh_head_ref }}-${{ matrix.parent_image_type }}
7889
uses: docker/build-push-action@v5
7990
with:
8091
context: .
81-
cache-from: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}-cache
82-
cache-to: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}-cache,mode=max,image-manifest=true
92+
cache-from: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ needs.configure-branch-name.outputs.gh_head_ref }}-${{ matrix.parent_image_type }}-cache
93+
cache-to: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ needs.configure-branch-name.outputs.gh_head_ref }}-${{ matrix.parent_image_type }}-cache,mode=max,image-manifest=true
8394
platforms: linux/amd64
8495
file: Dockerfile
85-
tags: ${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}
96+
tags: ${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ needs.configure-branch-name.outputs.gh_head_ref }}-${{ matrix.parent_image_type }}
8697
push: true
8798
build-args: |
8899
platform=linux/amd64
89100
label=dockerfile-path=https://github.com/refinery-${{ matrix.parent_image_type }}-parent-image/blob/${{ github.sha }}/Dockerfile
90101
91-
- name: Build & Push refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}-arm64
102+
- name: Build & Push refinery-parent-images:${{ needs.configure-branch-name.outputs.gh_head_ref }}-${{ matrix.parent_image_type }}-arm64
92103
uses: docker/build-push-action@v5
93104
with:
94105
context: .
95-
cache-from: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}-arm64-cache
96-
cache-to: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}-arm64-cache,mode=max,image-manifest=true
106+
cache-from: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ needs.configure-branch-name.outputs.gh_head_ref }}-${{ matrix.parent_image_type }}-arm64-cache
107+
cache-to: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ needs.configure-branch-name.outputs.gh_head_ref }}-${{ matrix.parent_image_type }}-arm64-cache,mode=max,image-manifest=true
97108
platforms: linux/arm64
98109
file: Dockerfile
99-
tags: ${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}-arm64
110+
tags: ${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ needs.configure-branch-name.outputs.gh_head_ref }}-${{ matrix.parent_image_type }}-arm64
100111
push: true
101112
build-args: |
102113
platform=linux/arm64

.github/workflows/pi_merge.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ env:
1313
GH_TOKEN: ${{ secrets.GH_TOKEN }}
1414

1515
jobs:
16+
configure-branch-name:
17+
name: 'Configure Head Branch Name'
18+
runs-on: ubuntu-latest
19+
outputs:
20+
gh_head_ref: ${{ steps.configure-branch-name.outputs.gh_head_ref }}
21+
steps:
22+
- name: Configure branch name
23+
id: configure-branch-name
24+
run: echo "gh_head_ref=$(echo "${{ github.event.pull_request.head.ref }}" | sed 's|/|-|g')" >> $GITHUB_OUTPUT
25+
1626
pi-matrix:
1727
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/pi_matrix.yml@dev
1828
secrets: inherit
@@ -23,7 +33,7 @@ jobs:
2333
pi-update-submodule:
2434
name: 'Parent Images: Submodules'
2535
runs-on: ubuntu-latest
26-
needs: [pi-matrix]
36+
needs: [pi-matrix, configure-branch-name]
2737
environment: dev
2838
env:
2939
PYTHON_VERSION: ${{ vars.PYTHON_VERSION }}
@@ -53,28 +63,28 @@ jobs:
5363
git checkout ${{ github.event.pull_request.base.ref }}
5464
5565
cd ${{ github.workspace }}
56-
git checkout ${{ github.event.pull_request.head.ref }} || git checkout -b ${{ github.event.pull_request.head.ref }}
57-
git push origin ${{ github.event.pull_request.head.ref }} && git pull origin ${{ github.event.pull_request.head.ref }}
66+
git checkout ${{ needs.configure-branch-name.outputs.gh_head_ref }} || git checkout -b ${{ needs.configure-branch-name.outputs.gh_head_ref }}
67+
git push origin ${{ needs.configure-branch-name.outputs.gh_head_ref }} && git pull origin ${{ needs.configure-branch-name.outputs.gh_head_ref }}
5868
5969
git config user.email "devtools@kern.ai"
6070
git config user.name "GitHub Actions"
6171
6272
git add submodules
63-
git commit -m "ci: update submodules to origin/${{ github.event.pull_request.head.ref }}" || true
64-
git push origin ${{ github.event.pull_request.head.ref }}
65-
echo "::notice::${{ github.event.repository.name }} updated to origin/${{ github.event.pull_request.head.ref }}"
73+
git commit -m "ci: update submodules to origin/${{ needs.configure-branch-name.outputs.gh_head_ref }}" || true
74+
git push origin ${{ needs.configure-branch-name.outputs.gh_head_ref }}
75+
echo "::notice::${{ github.event.repository.name }} updated to origin/${{ needs.configure-branch-name.outputs.gh_head_ref }}"
6676
6777
gh pr create --draft \
6878
--title "${{ github.event.pull_request.title }}" \
6979
--body "${{ github.event.pull_request.body }}" \
7080
--base dev \
71-
--head ${{ github.event.pull_request.head.ref }} \
81+
--head ${{ needs.configure-branch-name.outputs.gh_head_ref }} \
7282
--repo ${{ github.repository_owner }}/refinery-${{ matrix.parent_image_type }}-parent-image
7383
7484
pi-update-app:
7585
name: 'Parent Images: ' # suffix populated by matrix
7686
runs-on: ubuntu-latest
77-
needs: [pi-matrix]
87+
needs: [pi-matrix, configure-branch-name]
7888
environment: dev
7989
continue-on-error: true
8090
env:
@@ -117,18 +127,18 @@ jobs:
117127
git config user.email "devtools@kern.ai"
118128
git config user.name "GitHub Actions"
119129
120-
git checkout -b ${{ github.event.pull_request.head.ref }} || git checkout ${{ github.event.pull_request.head.ref }}
121-
git push origin ${{ github.event.pull_request.head.ref }} && git pull origin ${{ github.event.pull_request.head.ref }}
130+
git checkout -b ${{ needs.configure-branch-name.outputs.gh_head_ref }} || git checkout ${{ needs.configure-branch-name.outputs.gh_head_ref }}
131+
git push origin ${{ needs.configure-branch-name.outputs.gh_head_ref }} && git pull origin ${{ needs.configure-branch-name.outputs.gh_head_ref }}
122132
123133
git add requirements*
124134
git commit -m "ci: update ${{ matrix.parent_image_type }}-requirements.txt"
125-
git push origin ${{ github.event.pull_request.head.ref }}
126-
echo "::notice::${{ matrix.app }} updated to origin/${{ github.event.pull_request.head.ref }}"
135+
git push origin ${{ needs.configure-branch-name.outputs.gh_head_ref }}
136+
echo "::notice::${{ matrix.app }} updated to origin/${{ needs.configure-branch-name.outputs.gh_head_ref }}"
127137
128138
gh pr create --draft \
129139
--title "${{ github.event.pull_request.title }}" \
130140
--body "${{ github.event.pull_request.body }}" \
131141
--base dev \
132-
--head ${{ github.event.pull_request.head.ref }} \
142+
--head ${{ needs.configure-branch-name.outputs.gh_head_ref }} \
133143
--repo ${{ github.repository_owner }}/${{ matrix.app }}
134144

0 commit comments

Comments
 (0)