Skip to content

Commit

Permalink
improved GitHub workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
FaserF committed Feb 18, 2025
1 parent e946d7b commit 18e89d9
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 45 deletions.
1 change: 0 additions & 1 deletion .github/workflows/Bump-Addon-Version-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ jobs:
fi
done <<< "$files"
echo "🎉 Version increment process completed successfully!"
- name: Commit & Push
uses: actions-js/push@v1.5
with:
Expand Down
97 changes: 75 additions & 22 deletions .github/workflows/Bump-Addon-Version-netbootxyz.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Automatically bump version on netbootxyz updates and changelog

permissions:
Expand All @@ -12,48 +11,102 @@ on:
jobs:
version:
runs-on: ubuntu-latest
if: ${{ contains(github.event.head_commit.message, 'Update dependency netbootxyz/webapp') }} # Detect that the netbootxyz version has been updated
if: ${{ contains(github.event.head_commit.message, 'Update dependency netbootxyz/webapp') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
lfs: "true"
fetch-depth: 0

- name: "Retrieve version & increment it"
id: version
run: |
set -e
echo "Starting version increment process..."
configFiles=$(find netboot-xyz -name 'config.yaml' -print0 | xargs -r0 echo)
if [[ -z "$configFiles" ]]; then
echo "❌ Error: No config.yaml files found!"
exit 1
fi
echo "Found config files: $configFiles"
for configfile in $configFiles; do
OLD_VERSION=$(cat $configfile | grep 'version: ' | head -1 | sed s/"version: "//)
echo "--------------------------------------------"
echo "Processing: $configfile"
if [ ! -f "$configfile" ]; then
echo "❌ Error: $configfile not found!"
exit 1
fi
if [ ! -r "$configfile" ]; then
echo "❌ Error: $configfile is not readable! Trying to fix permissions..."
chmod +r "$configfile" || { echo "❌ Failed to fix permissions!"; exit 1; }
fi
OLD_VERSION=$(grep -E '^[[:space:]]*version:[[:space:]]+[0-9]+\.[0-9]+\.[0-9]+' "$configfile" | head -1 | awk '{print $2}')
if [[ -z "$OLD_VERSION" ]]; then
echo "❌ Error: Could not extract a valid version from $configfile"
cat "$configfile"
exit 1
fi
echo "Extracted OLD_VERSION: '$OLD_VERSION'"
IFS='.' read -r major minor patch <<< "$OLD_VERSION"
if [[ -z "$major" || -z "$minor" || -z "$patch" ]]; then
echo "❌ Error: Failed to parse version components from '$OLD_VERSION'."
exit 1
fi
((patch++))
NEW_VERSION="$major.$minor.$patch"
sed -i "s/$OLD_VERSION/$NEW_VERSION/g" $configfile
echo "Incremented addon $configfile from version $OLD_VERSION to $NEW_VERSION"
echo "Updating $configfile from version $OLD_VERSION to $NEW_VERSION"
sed -i "s/^version: $OLD_VERSION/version: $NEW_VERSION/" "$configfile" || {
echo "❌ Error: Failed to update version in $configfile"
exit 1
}
echo "✅ Successfully updated $configfile to version $NEW_VERSION"
done
echo "🎉 Version increment process completed successfully!"
- name: "Update Changelog"
id: changelog
run: |
set -e
echo "🔄 Starting changelog version increment process..."
repo_url="https://api.github.com/repos/netbootxyz/webapp"
response=$(curl -s "$repo_url/releases")
latest_version=$(echo "$response" | grep -oP '"tag_name": "\K[^"]+' | sed -n '1p')
find netboot-xyz -name "CHANGELOG.md" -exec grep -l "# Changelog" {} \; | while read -r file; do
current_version=$(grep -oP "^## \K\d+\.\d+\.\d+" "$file" | sort -rV | head -n1)
if [ -n "$current_version" ]; then
IFS='.' read -r major minor patch <<< "$current_version"
((patch++))
new_version="$major.$minor.$patch"
echo "Generated new version $new_version"
if sed -i "/# Changelog/a \\## $new_version\\n- automatically update netboot-xyz to version $latest_version\n" "$file" ; then
echo "Added changelog auto text for $file with new version $new_version and netboot-xyz version $latest_version"
else
echo "Error while writing changelog auto text for $file with new version $new_version and netboot-xyz version $latest_version"
fi
else
echo "No valid version found in $file"
fi
done
echo "✅ Latest version from repo: $latest_version"
files=$(find netboot-xyz -name "CHANGELOG.md" -exec grep -l "# Changelog" {} \;)
if [[ -z "$files" ]]; then
echo "❌ Error: No CHANGELOG.md files found!"
exit 1
fi
echo "Found changelog files: $files"
while IFS= read -r file; do
echo "Processing: $file"
current_version=$(grep -oP "^## \K\d+\.\d+\.\d+" "$file" | sort -rV | head -n1)
if [[ -z "$current_version" ]]; then
echo "⚠️ No valid version found in $file"
continue
fi
echo "Found current version: $current_version"
IFS='.' read -r major minor patch <<< "$current_version"
((patch++))
new_version="$major.$minor.$patch"
if ! sed -i "/# Changelog/a \\## $new_version\\n- Automatically updated netboot-xyz to version $latest_version\\n" "$file"; then
echo "❌ Error while writing changelog entry to $file"
exit 1
fi
echo "✅ Successfully updated $file with version $new_version"
done <<< "$files"
echo "🎉 Changelog update process completed successfully!"
- name: Commit & Push
uses: actions-js/push@v1.5
with:
Expand Down
97 changes: 75 additions & 22 deletions .github/workflows/Bump-Addon-Version-wikijs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Automatically bump version on wikijs updates and changelog

permissions:
Expand All @@ -12,48 +11,102 @@ on:
jobs:
version:
runs-on: ubuntu-latest
if: ${{ contains(github.event.head_commit.message, 'Update dependency requarks/wiki') }} # Detect that the wikijs version has been updated
if: ${{ contains(github.event.head_commit.message, 'Update dependency requarks/wiki') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
lfs: "true"
fetch-depth: 0

- name: "Retrieve version & increment it"
id: version
run: |
set -e
echo "Starting version increment process..."
configFiles=$(find wiki.js -name 'config.yaml' -print0 | xargs -r0 echo)
if [[ -z "$configFiles" ]]; then
echo "❌ Error: No config.yaml files found!"
exit 1
fi
echo "Found config files: $configFiles"
for configfile in $configFiles; do
OLD_VERSION=$(cat $configfile | grep 'version: ' | head -1 | sed s/"version: "//)
echo "--------------------------------------------"
echo "Processing: $configfile"
if [ ! -f "$configfile" ]; then
echo "❌ Error: $configfile not found!"
exit 1
fi
if [ ! -r "$configfile" ]; then
echo "❌ Error: $configfile is not readable! Trying to fix permissions..."
chmod +r "$configfile" || { echo "❌ Failed to fix permissions!"; exit 1; }
fi
OLD_VERSION=$(grep -E '^[[:space:]]*version:[[:space:]]+[0-9]+\.[0-9]+\.[0-9]+' "$configfile" | head -1 | awk '{print $2}')
if [[ -z "$OLD_VERSION" ]]; then
echo "❌ Error: Could not extract a valid version from $configfile"
cat "$configfile"
exit 1
fi
echo "Extracted OLD_VERSION: '$OLD_VERSION'"
IFS='.' read -r major minor patch <<< "$OLD_VERSION"
if [[ -z "$major" || -z "$minor" || -z "$patch" ]]; then
echo "❌ Error: Failed to parse version components from '$OLD_VERSION'."
exit 1
fi
((patch++))
NEW_VERSION="$major.$minor.$patch"
sed -i "s/$OLD_VERSION/$NEW_VERSION/g" $configfile
echo "Incremented addon $configfile from version $OLD_VERSION to $NEW_VERSION"
echo "Updating $configfile from version $OLD_VERSION to $NEW_VERSION"
sed -i "s/^version: $OLD_VERSION/version: $NEW_VERSION/" "$configfile" || {
echo "❌ Error: Failed to update version in $configfile"
exit 1
}
echo "✅ Successfully updated $configfile to version $NEW_VERSION"
done
echo "🎉 Version increment process completed successfully!"
- name: "Update Changelog"
id: changelog
run: |
set -e
echo "🔄 Starting changelog version increment process..."
repo_url="https://api.github.com/repos/requarks/wiki"
response=$(curl -s "$repo_url/releases")
latest_version=$(echo "$response" | grep -oP '"tag_name": "\K[^"]+' | sed -n '1p')
find wiki.js -name "CHANGELOG.md" -exec grep -l "# Changelog" {} \; | while read -r file; do
current_version=$(grep -oP "^## \K\d+\.\d+\.\d+" "$file" | sort -rV | head -n1)
if [ -n "$current_version" ]; then
IFS='.' read -r major minor patch <<< "$current_version"
((patch++))
new_version="$major.$minor.$patch"
echo "Generated new version $new_version"
if sed -i "/# Changelog/a \\## $new_version\\n- automatically update wikijs to version $latest_version\n" "$file" ; then
echo "Added changelog auto text for $file with new version $new_version and wikijs version $latest_version"
else
echo "Error while writing changelog auto text for $file with new version $new_version and wikijs version $latest_version"
fi
else
echo "No valid version found in $file"
fi
done
echo "✅ Latest version from repo: $latest_version"
files=$(find wiki.js -name "CHANGELOG.md" -exec grep -l "# Changelog" {} \;)
if [[ -z "$files" ]]; then
echo "❌ Error: No CHANGELOG.md files found!"
exit 1
fi
echo "Found changelog files: $files"
while IFS= read -r file; do
echo "Processing: $file"
current_version=$(grep -oP "^## \K\d+\.\d+\.\d+" "$file" | sort -rV | head -n1)
if [[ -z "$current_version" ]]; then
echo "⚠️ No valid version found in $file"
continue
fi
echo "Found current version: $current_version"
IFS='.' read -r major minor patch <<< "$current_version"
((patch++))
new_version="$major.$minor.$patch"
if ! sed -i "/# Changelog/a \\## $new_version\\n- Automatically updated wikijs to version $latest_version\\n" "$file"; then
echo "❌ Error while writing changelog entry to $file"
exit 1
fi
echo "✅ Successfully updated $file with version $new_version"
done <<< "$files"
echo "🎉 Changelog update process completed successfully!"
- name: Commit & Push
uses: actions-js/push@v1.5
with:
Expand Down

0 comments on commit 18e89d9

Please sign in to comment.