Skip to content

Commit

Permalink
New GitHub scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Best-Codes committed Jul 26, 2024
1 parent 462d1fc commit 37392b3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 43 deletions.
33 changes: 33 additions & 0 deletions .github/scripts/update-security.js
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);
61 changes: 19 additions & 42 deletions .github/workflows/update_security_md.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "best-bible",
"version": "1.5.1",
"version": "1.5.2",
"description": "Fetch, parse, and analyze the Bible easily with JavaScript",
"scripts": {
"build:cjs": "tsc --project tsconfig.cjs.json || true && mkdir -p dist/cjs/data && cp src/data/bible.json dist/cjs/data/",
Expand Down

0 comments on commit 37392b3

Please sign in to comment.