-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
138 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ on: | |
types: [opened, reopened, synchronize] | ||
|
||
workflow_dispatch: | ||
inputs: | ||
inputs: | ||
BRANCH_NAME: | ||
description: 'Specify branch name or PR (e.g. PR-41)' | ||
required: false | ||
|
@@ -20,7 +20,7 @@ on: | |
type: boolean | ||
description: 'Perform release, Defauls is false' | ||
required: false | ||
|
||
jobs: | ||
check-permission: | ||
runs-on: ubuntu-latest | ||
|
@@ -33,49 +33,89 @@ jobs: | |
github-repo: ${{ github.repository }} | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
check_changelog: | ||
update-changelog: | ||
if: github.event_name == 'pull_request' | ||
runs-on: ubuntu-latest | ||
outputs: | ||
was_updated: ${{ steps.check-change.outputs.change_detected }} | ||
check_commit: ${{ steps.check-changelog.outputs.check_commit }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v2 | ||
with: | ||
path: copy-repo | ||
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} | ||
ref: ${{ github.head_ref }} | ||
fetch-depth: 0 | ||
|
||
- name: Get changed files | ||
id: changed-files | ||
- name: Check for updated CHANGELOG.md using git | ||
id: check-changelog | ||
run: | | ||
cd copy-repo | ||
if ${{ github.event_name == 'pull_request' }}; then | ||
echo "changed_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT | ||
else | ||
echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT | ||
fi | ||
if git diff --name-only origin/${{ github.base_ref }} | grep -q "^CHANGELOG.md$"; then | ||
echo "CHANGELOG.md has been updated." | ||
echo "::set-output name=check_commit::true" | ||
else | ||
echo "ERROR: CHANGELOG.md has not been updated." | ||
echo "::set-output name=check_commit::false" | ||
fi | ||
- name: Compare PR description with template | ||
if: steps.check-changelog.outputs.check_commit == 'false' | ||
env: | ||
PR_DESCRIPTION: ${{ github.event.pull_request.body }} | ||
run: | | ||
# Safely print the PR description using Node.js | ||
node -e "const fs=require('fs'); fs.writeFileSync('/tmp/pr_description.txt', process.env.PR_DESCRIPTION);" | ||
# Use diff to compare the two files | ||
if diff -wB /tmp/pr_description.txt .github/pull_request_template.md > /dev/null; then | ||
echo "ERROR: PR description is identical to the template." | ||
exit 1 | ||
else | ||
echo "PR description and template are different." | ||
fi | ||
- name: List changed files | ||
id: set-flag | ||
- name: Check PR body against changelog | ||
if: steps.check-changelog.outputs.check_commit == 'false' | ||
id: extract-changelog | ||
run: | | ||
cd copy-repo | ||
for file in ${{ steps.changed-files.outputs.changed_files }}; do | ||
echo "$file was changed" | ||
if [[ $file == "CHANGELOG.md" ]] | ||
then | ||
echo "file-flag=true" >> $GITHUB_OUTPUT | ||
break; | ||
else | ||
echo "file-flag=false" >> $GITHUB_OUTPUT | ||
fi | ||
done | ||
- name: Check if CHANGELOG is Updated and Abort if not updated | ||
if: steps.set-flag.outputs.file-flag != 'true' | ||
result=$(node .github/workflows/set-changelog.js ${{ github.event.pull_request.number }}) | ||
if [ "$result" = "Success" ]; then | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Zowe Robot" | ||
git add CHANGELOG.md | ||
git commit -s -m "Update changelog with PR #${{ github.event.pull_request.number }} description" | ||
git push | ||
echo "Updated CHANGELOG from description" | ||
else | ||
echo $result | ||
echo -e "No changelog and version information found in PR description. Please add them.\nExpected Format:\nVERSION:X.XX.X\nCHANGELOG:This is changelog note.\nTo re-run the action, just make a push or commit after updating the PR description or updating the changelog via a manual file changing commit." | ||
exit 1 | ||
fi | ||
- name: check for changes | ||
id: check-change | ||
run: | | ||
echo "CHANGELOG.md not updated, please update CHANGELOG.md with the changes made in the pull request" | ||
exit 1 | ||
if git diff --name-only HEAD^ HEAD | grep 'changelog.md'; then | ||
echo "No Changes detected, setting flag to false" | ||
echo "::set-output name=change_detected::false" | ||
else | ||
echo "::set-output name=change_detected::true" | ||
fi | ||
- name: Remove copy-repo | ||
if: always() | ||
run: rm -r copy-repo | ||
check_changelog: | ||
if: github.event_name == 'pull_request' | ||
needs: update-changelog | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Verify Changelog update | ||
run: | | ||
if [ "${{ needs.update-changelog.outputs.was_updated }}" != "true" ]; then | ||
echo "CHANGELOG.md not updated, please update CHANGELOG.md with the changes made in the pull request" | ||
exit 1 | ||
else | ||
echo "changelog was updated successfully." | ||
fi | ||
build: | ||
runs-on: ubuntu-latest | ||
|
@@ -129,11 +169,11 @@ jobs: | |
|
||
- name: '[Prep 8] Deploy ' | ||
uses: zowe-actions/zlux-builds/plugins/[email protected]/main | ||
|
||
- name: '[Prep 9] Bump Staging Version ' | ||
if: ${{ github.event.inputs.PERFORM_RELEASE == 'true' && env.RELEASE == 'true' }} | ||
uses: zowe-actions/zlux-builds/plugins/[email protected]/main | ||
env: | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.ZOWE_ROBOT_TOKEN }} | ||
|
||
- name: '[Prep 10] NodeJS project setup' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
This program and the accompanying materials are | ||
made available under the terms of the Eclipse Public License v2.0 which accompanies | ||
this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html | ||
SPDX-License-Identifier: EPL-2.0 | ||
Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
|
||
// Must run with args: PR_NUMBER | ||
const PR_NUMBER = process.argv[2]; | ||
const description = fs.readFileSync('/tmp/pr_description.txt', 'utf8'); | ||
let changelogMsg, version; | ||
|
||
if (description.includes('VERSION:') && description.includes('CHANGELOG:')) { | ||
let lines = description.split('\n'); | ||
lines.forEach((line) => { | ||
if (line.startsWith('CHANGELOG:')) { | ||
changelogMsg = line.substring('CHANGELOG:'.length).trim(); | ||
} else if (line.startsWith('VERSION:')) { | ||
version = line.substring('VERSION:'.length).trim(); | ||
} | ||
}); | ||
|
||
if (changelogMsg && version) { | ||
let changelog = fs.readFileSync('CHANGELOG.md', 'utf8'); | ||
let changelogLines = changelog.split('\n'); | ||
let versionIndex = -1; | ||
let anchorIndex = 0; | ||
for (let i = 0; i < changelogLines.length; i++) { | ||
if (changelogLines[i].includes('All notable changes to the sample angular app will be documented in this file.')) { | ||
anchorIndex = i; | ||
} else if (changelogLines[i].startsWith('## ' + version)) { // Removed "v" prefix | ||
versionIndex = i; | ||
break; | ||
} | ||
} | ||
if (versionIndex != -1) { | ||
changelogLines.splice(versionIndex + 2, 0, `- ${changelogMsg} (#${PR_NUMBER})`); | ||
} else { | ||
changelogLines.splice(anchorIndex + 1, 0, `\n## ${version}\n- ${changelogMsg} (#${PR_NUMBER})`); | ||
} | ||
const newChangelog = changelogLines.join('\n'); | ||
fs.writeFileSync('CHANGELOG.md', newChangelog); | ||
console.log('Success'); | ||
} else { | ||
if (!changelogMsg) { | ||
console.log('Missing CHANGELOG'); | ||
} | ||
if (!version) { | ||
console.log('Missing VERSION'); | ||
} | ||
} | ||
} else { | ||
console.log('Missing CHANGELOG or VERSION'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters