Skip to content

Commit 088364b

Browse files
authored
Merge pull request #13674 from huiwangredhat/squash_multiple_commits
Add step to sync-cac-oscal to squash multiple commits
2 parents 759a4c3 + b3a0c88 commit 088364b

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,42 @@ jobs:
265265
done
266266
fi
267267
done
268-
# Step 14: Create PR in OSCAL content
269-
- name: Create a Pull Request in OSCAL content
268+
# Step 14: Squash multiple commits
269+
- name: Squash multiple commits
270270
if: ${{ env.CHANGE_FOUND == 'true' }}
271+
run: |
272+
cd oscal-content
273+
BRANCH_NAME="sync_cac_pr${{ env.PR_NUMBER }}"
274+
git config user.name "openscap-ci"
275+
git config user.email "openscap-ci@gmail.com"
276+
echo "PR_SKIP=false" >> $GITHUB_ENV
277+
if [ "$(git branch --show-current)" == "$BRANCH_NAME" ]; then
278+
SQUASH_COUNT=$(git rev-list --count main..HEAD)
279+
if [[ "$SQUASH_COUNT" -eq 0 ]]; then
280+
echo "No commit of the branch."
281+
echo "PR_SKIP=true" >> $GITHUB_ENV
282+
elif [[ "$SQUASH_COUNT" -eq 1 ]]; then
283+
echo "::notice::Branch has 1 commit. No squashing needed."
284+
else
285+
# Call the squash script using the commit count
286+
$GITHUB_WORKSPACE/complyscribe/scripts/squash.sh "$SQUASH_COUNT"
287+
fi
288+
else
289+
echo "PR_SKIP=true" >> $GITHUB_ENV
290+
echo "No branch $BRANCH_NAME. Skipping squash and create PR."
291+
fi
292+
shell: bash
293+
env:
294+
GH_TOKEN: ${{ env.INSTALLATION_TOKEN }}
295+
# Step 15: Create PR in OSCAL content
296+
- name: Create a Pull Request in OSCAL content
297+
if: ${{ env.PR_SKIP == 'false' }}
271298
run: |
272299
cd oscal-content
273300
BRANCH_NAME="sync_cac_pr${{ env.PR_NUMBER }}"
274301
OWNER="ComplianceAsCode"
275302
REPO="oscal-content"
276-
CAC_PR_URL="https://github.com/$OWNER/$REPO/pull/${{ env.PR_NUMBER }}"
303+
CAC_PR_URL="https://github.com/$OWNER/content/pull/${{ env.PR_NUMBER }}"
277304
if [[ "$(git branch --show-current)" == "$BRANCH_NAME" ]]; then
278305
# Check if the PR exists
279306
PR_EXISTS=$(gh pr list --repo $OWNER/$REPO \

0 commit comments

Comments
 (0)