Skip to content

Bump dev version in tudat and tudat-feedstock if new commit in last 24 hours #52

Bump dev version in tudat and tudat-feedstock if new commit in last 24 hours

Bump dev version in tudat and tudat-feedstock if new commit in last 24 hours #52

# This workflow is triggered at 01:00 AM CET everyday and checks if there has
# been a commit in the last 24 hours on the develop branch of tudat repository.
# If there has been a commit, it bumps the version in the develop branch of
# the tudat repository, creates a tag with the version numbers and pushes both
# the commit and the tag to the repository, and then bumps the version in the
# develop branch of the tudat-feedstock repository and pushes the commit and
# the tag to the repository.
# This workflow uses personal access tokens to push the changes to the repository. The personal access token is stored as a secret in the repository.
# This workflow file must be in the master (default branch) of the tudat repository because scheduled workflows are only triggered on the default branch.
# Reference for the logic to check if there has been a commit in the last 24 hours: https://stackoverflow.com/questions/4089430/how-can-i-determine-if-a-git-commit-is-more-recent-than-another-commit
name: Bump dev version in tudat and tudat-feedstock if new commit in last 24 hours
on:
schedule:
- cron: '0 0 * * *' # This triggers the workflow daily at 0:00 AM UTC.
workflow_dispatch: # This facilitates manual triggering of the workflow from the Actions tab of the repository in case the scheduled run fails.
permissions:
contents: write
actions: write
jobs:
check_recent_24h_commit:
runs-on: ubuntu-latest
name: Check latest commit
outputs:
should_run: ${{ steps.should_bump_version.outputs.should_run }}
steps:
- uses: actions/checkout@v4
with:
ref: develop # Check the latest commit on the develop branch of tudat repository
- name: print latest_commit
run: git log -n 1 --pretty=format:"%H"
- id: should_bump_version
continue-on-error: true
name: check latest commit is less than a day
run: |
STR=$(git rev-list --after="24 hours" $(git log -n 1 --pretty=format:"%H"))
if test -z $STR; then
echo "should_run=false" >> $GITHUB_OUTPUT
else
echo "should_run=true" >> $GITHUB_OUTPUT
fi
# If the latest commit is less than 24 hours old, the command git rev-list --after="24 hours" $(git log -n 1 --pretty=format:"%H") will return a non-empty string (list of commit ids in the last 24 hours), which will cause the test -z command to return false and the output should_run will not be set to false.
# test -z $STR checks if $STR is empty or not. If it is empty, it returns true, else false.
bump-version_tudat:
needs: check_recent_24h_commit
if: ${{ needs.check_recent_24h_commit.outputs.should_run != 'false' && github.event_name == 'schedule' }}
runs-on: ubuntu-latest
name: Bump version in tudat repository
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: develop
- name: Install bump2version and run bumpversion
run: |
python3 -m venv venv
source venv/bin/activate
pip install bump2version
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
bump2version dev --config-file .bumpversion.cfg --verbose
- name: Push tag to tudat repository
run: git push origin --follow-tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
bump_version_tudat_feedstock:
needs: check_recent_24h_commit
if: ${{ needs.check_recent_24h_commit.outputs.should_run != 'false' && github.event_name == 'schedule' }}
runs-on: ubuntu-latest
name: bump version and create tag in tudat-feedstock
steps:
- name: checkout tudat-feedstock
uses: actions/checkout@v4
with:
repository: tudat-team/tudat-feedstock
token: ${{ secrets.BUMP_VERSION_NIGHTLY }}
ref: develop
- name: Install bump2version and run bumpversion
run: |
python3 -m venv venv
source venv/bin/activate
pip install bump2version
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
bump2version dev --config-file .bumpversion.cfg --verbose
- name: Reset build number in meta.yml to 0
shell: bash
run: |
sed -i 's/build = ".*" %}/build = "0" %}/' recipe/meta.yaml
git add recipe/meta.yaml
git commit --amend --no-edit
- name: Push tag to tudat-feedstock
run: git push origin --follow-tags
env:
GITHUB_TOKEN: ${{ secrets.BUMP_VERSION_NIGHTLY}}