Skip to content

Commit 1704b17

Browse files
committed
fix(ci): Update store-type merge logic to handle ref=main and not commit to this repo's main.
Signed-off-by: spbsoluble <[email protected]>
1 parent 2f44792 commit 1704b17

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

.github/workflows/update-stores.yml

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ jobs:
2828
run: |
2929
echo "TARGET_REPO_BRANCH=${{ github.event.client_payload.targetRef }}" | tee -a $GITHUB_ENV
3030
echo "KFUTIL_ARG=${{ github.event.client_payload.targetRepo }}" | tee -a $GITHUB_ENV
31+
- name: Set Branch Name based on targetRef
32+
id: set-branch-name
33+
run: |
34+
if [ "${{ env.TARGET_REPO_BRANCH }}" == "main" ]; then
35+
echo "BRANCH_NAME=${{ env.KFUTIL_ARG }}_${{ env.TARGET_REPO_BRANCH }}" | tee -a $GITHUB_ENV
36+
else
37+
echo "BRANCH_NAME=${{ env.KFUTIL_ARG }}" | tee -a $GITHUB_ENV
38+
fi
39+
3140
- name: Check Open PRs for Existing Branch
3241
id: check-branch
3342
uses: actions/github-script@v7
@@ -41,8 +50,8 @@ jobs:
4150
repo,
4251
state: "open"
4352
});
44-
// Filter out ones matching the KFUTIL_ARG from payload (repository_dispatch) or input (workflow_dispatch)
45-
const filteredData = pulls.data.filter(item => item.head.ref === '${{ env.KFUTIL_ARG }}'); // Look for an existing branch with the orchestrator repo name
53+
// Filter out ones matching our branch naming convention
54+
const filteredData = pulls.data.filter(item => item.head.ref === '${{ env.BRANCH_NAME }}');
4655
const isBranch = (filteredData.length > 0)
4756
if (isBranch) {
4857
const {
@@ -54,25 +63,25 @@ jobs:
5463
} else {
5564
core.setOutput('PR_BRANCH', 'create') // No branch, create one
5665
}
57-
console.log(`Branch exists?`)
58-
console.log(filteredData.length > 0)
59-
console.log(`targetRepo: ${{env.KFUTIL_ARG}}`)
66+
console.log(`Branch exists? ${filteredData.length > 0}`)
67+
console.log(`Branch name: ${{env.BRANCH_NAME}}`)
68+
6069
- name: set env.PR_BRANCH value for jobs
6170
run: |
6271
echo "PR_BRANCH=${{steps.check-branch.outputs.PR_BRANCH}}" | tee -a $GITHUB_ENV
6372
6473
# If the branch with an open PR already exists, first check out that branch from kfutil
6574
- name: Check out existing repo merge branch
66-
if: env.PR_BRANCH == 'commit'
67-
uses: actions/checkout@v4
68-
with:
69-
repository: 'keyfactor/kfutil'
70-
sparse-checkout: |
71-
.github
72-
cmd
73-
path: './merge-folder/'
74-
token: ${{ secrets.V2BUILDTOKEN }}
75-
ref: '${{env.KFUTIL_ARG}}'
75+
if: env.PR_BRANCH == 'commit'
76+
uses: actions/checkout@v4
77+
with:
78+
repository: 'keyfactor/kfutil'
79+
sparse-checkout: |
80+
.github
81+
cmd
82+
path: './merge-folder/'
83+
token: ${{ secrets.V2BUILDTOKEN }}
84+
ref: '${{env.BRANCH_NAME}}'
7685

7786
# If the branch does not exist, first check out the main branch from kfutil.
7887
- name: Check out main
@@ -160,13 +169,13 @@ jobs:
160169
GITHUB_TOKEN: ${{ secrets.SDK_SYNC_PAT }}
161170
with:
162171
add: |
163-
store_types.json
172+
store_types.json
164173
./cmd/store_types.json --force
165174
message: Update store_types.json for ${{env.KFUTIL_ARG}}:${{env.TARGET_REPO_BRANCH}}
166175
author_name: Keyfactor
167176
author_email: [email protected]
168177
cwd: './merge-folder/'
169-
new_branch: ${{env.KFUTIL_ARG}}
178+
new_branch: ${{env.BRANCH_NAME}}
170179

171180
- name: Add and Commit to existing branch
172181
if: ${{ env.UPDATE_FILE == 'T' && env.PR_BRANCH == 'commit' }}
@@ -187,18 +196,14 @@ jobs:
187196
uses: actions/github-script@v7
188197
with:
189198
script: |
190-
console.log(`Created ${{env.KFUTIL_ARG}} `)
191-
console.log("Commit to ${{env.KFUTIL_ARG}} for PR")
199+
console.log(`Created ${{env.BRANCH_NAME}} `)
200+
console.log("Commit to ${{env.BRANCH_NAME}} for PR")
192201
const owner = context.repo.owner;
193202
const repo = context.repo.repo;
194-
195-
// Get the current branch name that the workflow is running on
196-
const baseBranch = context.payload.ref ?
203+
const baseBranch = context.payload.ref ?
197204
context.payload.ref.replace('refs/heads/', '') : 'main';
198-
199205
console.log(`Base branch for PR: ${baseBranch}`);
200-
201-
const newBranch = '${{env.KFUTIL_ARG}}';
206+
const newBranch = '${{env.BRANCH_NAME}}';
202207
const response = await github.rest.pulls.create({
203208
owner,
204209
repo,
@@ -208,5 +213,3 @@ jobs:
208213
body: 'The cert store update from ${{env.KFUTIL_ARG}}:${{env.TARGET_REPO_BRANCH}} needs to be verified and merged if correct.',
209214
});
210215
console.log(`Pull request created: ${{env.KFUTIL_ARG}}:${{env.TARGET_REPO_BRANCH}} : ${response.data.html_url}`);
211-
env:
212-
GITHUB_TOKEN: ${{ secrets.V2BUILDTOKEN }}

0 commit comments

Comments
 (0)