-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
462d1fc
commit 37392b3
Showing
3 changed files
with
53 additions
and
43 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Helper function to get supported versions | ||
function getSupportedVersions(currentVersion) { | ||
const supportedVersions = ["1.4.5", "1.1.5"]; | ||
const [major, minor, patch] = currentVersion.split('.').map(Number); | ||
|
||
supportedVersions.push(currentVersion); | ||
if (patch > 1) supportedVersions.push(`${major}.${minor}.${patch - 1}`); | ||
if (patch > 0) supportedVersions.push(`${major}.${minor}.${patch - 2}`); | ||
|
||
return supportedVersions; | ||
} | ||
|
||
// Function to update SECURITY.md | ||
function updateSecurityMd(currentVersion) { | ||
const filePath = path.join(__dirname, '../../SECURITY.md'); | ||
const content = fs.readFileSync(filePath, 'utf-8'); | ||
|
||
const supportedVersions = getSupportedVersions(currentVersion); | ||
const supportedRows = supportedVersions.map(v => `| ${v} | :white_check_mark: |`).join('\n'); | ||
|
||
const updatedContent = content.replace( | ||
/\| Version \| Supported\s*\|([\s\S]*?)\| 1\.0\.0 \| :x: \|/, | ||
`| Version | Supported |\n| ------- | ------------------ |\n${supportedRows}\n| 1.0.0 | :x: |` | ||
); | ||
|
||
fs.writeFileSync(filePath, updatedContent); | ||
} | ||
|
||
const currentVersion = process.argv[2]; | ||
updateSecurityMd(currentVersion); |
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 |
---|---|---|
|
@@ -5,57 +5,34 @@ on: | |
types: [created] | ||
|
||
jobs: | ||
update-security-md: | ||
update-security: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: "14" | ||
|
||
- name: Update SECURITY.md | ||
run: | | ||
VERSION=$(node -p "require('./package.json').version") | ||
SECURITY_FILE="SECURITY.md" | ||
# Read current content | ||
CONTENT=$(cat $SECURITY_FILE) | ||
# Extract current versions from the table | ||
VERSIONS=$(echo "$CONTENT" | sed -n '/^| Version/,/^$/p' | grep -oP '^\| \d+\.\d+\.\d+' | awk '{print $2}' | sort -Vr) | ||
node-version: '16' | ||
|
||
# Prepare new versions list | ||
NEW_VERSIONS="$VERSION\n$(echo "$VERSIONS" | head -n 2)" | ||
NEW_VERSIONS+=$'\n1.4.5\n1.1.5' | ||
- name: Install dependencies | ||
run: npm install | ||
|
||
# Generate new table content | ||
TABLE_CONTENT="| Version | Supported |\n| ------- | ------------------ |\n" | ||
TABLE_CONTENT+="| (_Latest version is always supported_) | :white_check_mark: |\n" | ||
- name: Get current version | ||
id: get_version | ||
run: echo "::set-output name=version::$(node -p "require('./package.json').version")" | ||
|
||
while IFS= read -r ver; do | ||
if [[ "$ver" == "$VERSION" || "$ver" == "1.4.5" || "$ver" == "1.1.5" || $(echo -e "$NEW_VERSIONS" | head -n 3 | grep -q "$ver") ]]; then | ||
TABLE_CONTENT+="| $ver | :white_check_mark: |\n" | ||
else | ||
TABLE_CONTENT+="| $ver | :x: |\n" | ||
fi | ||
done <<< "$(echo -e "$NEW_VERSIONS\n$VERSIONS" | sort -Vr | uniq)" | ||
# Update only the table in the file | ||
sed -i '/^| Version/,/^$/c\'"$TABLE_CONTENT" $SECURITY_FILE | ||
- name: Update SECURITY.md | ||
run: node .github/scripts/update-security.js ${{ steps.get_version.outputs.version }} | ||
|
||
- name: Commit and push changes | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Commit changes | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git fetch origin | ||
git checkout main | ||
git pull origin main | ||
git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --local user.name "github-actions[bot]" | ||
git add SECURITY.md | ||
git commit -m "Update SECURITY.md for new release" || exit 0 | ||
git commit -m "Update SECURITY.md for version ${{ steps.get_version.outputs.version }}" | ||
git push | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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