Skip to content

Check and Update Lonesnake Version #338

Check and Update Lonesnake Version

Check and Update Lonesnake Version #338

name: Check and Update Lonesnake Version
on:
schedule:
- cron: "0 4 * * *" # Runs daily at 04:00 UTC
workflow_dispatch: # Allows manual triggering
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Need to get all branches so we can check if update branch has already been created
fetch-depth: "0"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install beautifulsoup4 requests
- name: Get current prog version and next prog version and generate branch name
id: version_definitions
run: |
current_prog_version="$(./release.py current-prog-version)"
echo "Current version of lonesnake: ${current_prog_version}"
echo "current_prog_version=${current_prog_version}" >> $GITHUB_OUTPUT
next_prog_version="$(./release.py next-prog-version)"
echo "Next version will be: $next_prog_version"
echo "next_prog_version=$next_prog_version" >> $GITHUB_OUTPUT
echo "new_branch_name=version-update/${next_prog_version}" >> $GITHUB_OUTPUT
- name: Check for updates
id: check_updates
run: |
if git branch -r | grep "origin/${{ steps.version_definitions.outputs.new_branch_name }}"; then
echo "Version update branch '${{ steps.version_definitions.outputs.new_branch_name }}' already exists."
current_branch="$(git rev-parse --abbrev-ref HEAD)"
git checkout "${{ steps.version_definitions.outputs.new_branch_name }}"
new_branch_updates_output="$(./release.py is-new-update-available)"
git checkout "$current_branch"
if [[ ! "$new_branch_updates_output" =~ "NO UPDATE AVAILABLE" ]]; then
echo "Error: Release ${{ steps.version_definitions.outputs.next_prog_version }}" \
"does not have the latest CPython releases, please merge pull request associated to" \
"'${{ steps.version_definitions.outputs.new_branch_name }}', then" \
"re-run the job" >&2
exit 1
fi
echo "Version update branch '${{ steps.version_definitions.outputs.new_branch_name }}'" \
"has the latest CPython releases."
echo "has_new_updates=0" >> $GITHUB_OUTPUT
exit 0
fi
has_new_updates=1
current_branch_updates_output="$(./release.py is-new-update-available)"
if [[ "$current_branch_updates_output" =~ "NO UPDATE AVAILABLE" ]]; then
echo "CPython releases in lonesnake are up-to-date"
has_new_updates=0
else
echo "$current_branch_updates_output"
fi
echo "has_new_updates=${has_new_updates}" >> $GITHUB_OUTPUT
- name: Update patch block and prog version
if: steps.check_updates.outputs.has_new_updates == 1
run: |
./release.py overwrite-latest-patch-block
./release.py overwrite-prog-version ${{ steps.version_definitions.outputs.next_prog_version }}
- name: Create branch and commit changes
if: steps.check_updates.outputs.has_new_updates == 1
run: |
git config user.name "GitHub Actions Bot"
git config user.email "actions@github.com"
git checkout -b "${{ steps.version_definitions.outputs.new_branch_name }}"
git add README.md lonesnake helpers/lonesnake-kit
git commit -m "Update lonesnake from ${{ steps.version_definitions.outputs.current_prog_version }} to ${{ steps.version_definitions.outputs.next_prog_version }} with new CPython patch versions"
git push origin "${{ steps.version_definitions.outputs.new_branch_name }}"
git tag "${{ steps.version_definitions.outputs.next_prog_version }}"
git push --tags
id: create_branch
- name: Create Pull Request
if: steps.check_updates.outputs.has_new_updates == 1
uses: actions/github-script@v7
with:
script: |
const { repo, owner } = context.repo;
const result = await github.rest.pulls.create({
owner,
repo,
title: `Update lonesnake version to ${process.env.NEXT_VERSION} with new CPython versions`,
body: `Automated update of Lonesnake from ${process.env.CURRENT_VERSION} to ${process.env.NEXT_VERSION}`,
head: process.env.BRANCH_NAME,
base: 'main'
});
// Add the 'release' label to the pull request
await github.rest.issues.addLabels({
owner,
repo,
issue_number: result.data.number,
labels: ['release']
});
console.log(`Pull Request created: ${result.data.html_url}`);
env:
CURRENT_VERSION: ${{ steps.version_definitions.outputs.current_prog_version }}
NEXT_VERSION: ${{ steps.version_definitions.outputs.next_prog_version }}
BRANCH_NAME: ${{ steps.version_definitions.outputs.new_branch_name }}