Skip to content

Commit 7215917

Browse files
committed
minor improvement for trigger event and check existing branch
Signed-off-by: Sophia Wang <huiwang@redhat.com>
1 parent 5cfca69 commit 7215917

1 file changed

Lines changed: 34 additions & 5 deletions

File tree

.github/workflows/sync-oscal-cac.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@ permissions:
33
contents: write
44
pull-requests: read
55
on:
6-
push:
7-
branches:
8-
- main
6+
# push:
7+
# branches:
8+
# - main
9+
# The sync-oscal-content CLI could change the format of controls and profiles.
10+
# It's hard to review for CAC reviewers. The story CPLYTM-652 could help to
11+
# improve the pain point. To aviod the noise in the early stage, the trigger
12+
# event is changed to workflow_dispatch.
13+
# trigger.
14+
# https://github.com/ComplianceAsCode/content/pull/13617#issuecomment-3000489965
15+
workflow_dispatch:
916

1017
jobs:
1118
sync-oscal-content-update-to-cac:
@@ -96,7 +103,29 @@ jobs:
96103
cd complyscribe && python3 -m venv venv && source venv/bin/activate
97104
python3 -m pip install --no-cache-dir "poetry==1.7.1"
98105
poetry install
99-
# Step 8: Sync OSCAL content to CAC content
106+
# Step 8: Check if the CAC content branch exists
107+
- name: Check if the CAC content branch exists
108+
if: ${{ env.CHANGE_FOUND == 'true' }}
109+
run: |
110+
pr_number="${{ github.event.pull_request.number }}"
111+
BRANCH_NAME="sync_oscal_pr$pr_number"
112+
cd cac-content
113+
branches=$(git branch -r | grep 'origin/sync_oscal' | sed 's/origin\///')
114+
exist="false"
115+
for branch in $branches; do
116+
echo $branch
117+
if [[ "$branch" == "$BRANCH_NAME" ]]; then
118+
echo "CAC content branch $BRANCH_NAME exists"
119+
git fetch --all
120+
git checkout -b "sync_oscal_pr$pr_number" origin/sync_oscal_pr$pr_number
121+
exist="true"
122+
break
123+
fi
124+
done
125+
if [[ "$exist" == "false" ]]; then
126+
echo "CAC content branch $BRANCH_NAME doesn't exist"
127+
fi
128+
# Step 9: Sync OSCAL content to CAC content
100129
- name: Sync OSCAL content to CAC content
101130
if: ${{ env.CHANGE_FOUND == 'true' }}
102131
run: |
@@ -123,7 +152,7 @@ jobs:
123152
poetry run complyscribe sync-oscal-content component-definition --repo-path ../oscal-content --committer-email "openscap-ci@gmail.com" --committer-name "openscap-ci" --branch "sync_oscal_pr$pr_number" --cac-content-root "$GITHUB_WORKSPACE/cac-content" --product "$product" --oscal-profile "$profile"
124153
fi
125154
done < ../filenames.txt
126-
# Step 9: Create PR to CAC content
155+
# Step 10: Create PR to CAC content
127156
- name: Create a Pull Request to OSCAL content
128157
if: ${{ env.CHANGE_FOUND == 'true' }}
129158
run: |

0 commit comments

Comments
 (0)