Fetch Tomcat Versions #12
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
name: Fetch Tomcat Versions | |
on: | |
schedule: | |
- cron: '* * * * *' # Runs at midnight on every 10th day of the month | |
jobs: | |
fetch_tomcat_versions: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Fetch latest Tomcat versions | |
id: fetch_versions | |
run: | | |
# Fetch the latest Tomcat major version number | |
MAJOR_VERSION=$(curl -s https://dlcdn.apache.org/tomcat/ | grep -oP 'tomcat-[0-9]+' | sort -V | tail -1 | grep -oP '[0-9]+') | |
# Fetch the latest Tomcat version number within the major version | |
TOMCAT_VERSION=$(curl -s https://dlcdn.apache.org/tomcat/tomcat-${MAJOR_VERSION}/ | grep -oP 'v\d+\.\d+\.\d+.*?/' | sort -V | tail -n 1 | sed 's/\/$//') | |
# Check if the version has changed | |
CURRENT_MAJOR_VERSION=$(grep -oP 'MAJOR_VERSION=\K[0-9]+' tomcat.sh) | |
CURRENT_TOMCAT_VERSION=$(grep -oP 'TOMCAT_VERSION=\K[0-9]+\.[0-9]+\.[0-9]+' tomcat.sh) | |
echo "Current Major Version: ${CURRENT_MAJOR_VERSION}" | |
echo "Fetched Major Version: ${MAJOR_VERSION}" | |
echo "Current Tomcat Version: ${CURRENT_TOMCAT_VERSION}" | |
echo "Fetched Tomcat Version: ${TOMCAT_VERSION}" | |
if [ "${CURRENT_MAJOR_VERSION}" != "${MAJOR_VERSION}" ] || [ "${CURRENT_TOMCAT_VERSION}" != "${TOMCAT_VERSION}" ]; then | |
echo "Versions differ, updating tomcat.sh..." | |
sed -i "s/^MAJOR_VERSION=.*$/MAJOR_VERSION=${MAJOR_VERSION}/" tomcat.sh | |
sed -i "s/^TOMCAT_VERSION=.*$/TOMCAT_VERSION=${TOMCAT_VERSION}/" tomcat.sh | |
echo "Versions updated." | |
echo "::set-output name=update_needed::true" | |
else | |
echo "No update needed." | |
echo "::set-output name=update_needed::false" | |
fi | |
- name: Commit updated Tomcat versions | |
if: steps.fetch_version.outputs.update_needed == 'true' | |
run: | | |
git config --local user.name "GitHub Actions" | |
git config --local user.email "actions@github.com" | |
git add tomcat.sh | |
git commit -m "Update Tomcat.sh file" | |
git push |