Improvement: Automate the creation of a version tag on a monthly basis #1
Workflow file for this run
This file contains hidden or 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: Create a new version tag | |
| # This file is part of t8code. | |
| # t8code is a C library to manage a collection (a forest) of multiple | |
| # connected adaptive space-trees of general element types in parallel. | |
| # | |
| # Copyright (C) 2024 the developers | |
| # | |
| # t8code is free software; you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation; either version 2 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # t8code is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU General Public License | |
| # along with t8code; if not, write to the Free Software Foundation, Inc., | |
| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| on: | |
| pull_request: | |
| workflow_dispatch: | |
| schedule: | |
| # trigger at 0:00 on the first day of each month | |
| - cron: '0 0 1 * *' | |
| jobs: | |
| monthly_release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| #checkout main branch | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| ref: main | |
| persist-credentials: false | |
| # Get the current version from the latest tag | |
| - name: Get latest tag | |
| id: get_latest_tag | |
| run: | | |
| LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) | |
| echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV | |
| echo "LATEST_TAG=$LATEST_TAG" | |
| # Get Major, Minor, Patch version numbers | |
| - name: Parse version numbers | |
| id: parse_version | |
| run: | | |
| VERSION_REGEX="v([0-9]+)\\.([0-9]+)\\.([0-9]+)" | |
| if [[ "${{ env.LATEST_TAG }}" =~ $VERSION_REGEX ]]; then | |
| MAJOR="${BASH_REMATCH[1]}" | |
| MINOR="${BASH_REMATCH[2]}" | |
| PATCH="${BASH_REMATCH[3]}" | |
| echo "MAJOR=$MAJOR" >> $GITHUB_ENV | |
| echo "MINOR=$MINOR" >> $GITHUB_ENV | |
| echo "PATCH=$PATCH" >> $GITHUB_ENV | |
| echo "MAJOR=$MAJOR, MINOR=$MINOR, PATCH=$PATCH" | |
| else | |
| echo "No valid tag found, aborting." | |
| exit 1 | |
| fi | |
| # Create version name accessible in the following steps | |
| - name: Set version name | |
| run: echo "VERSION_NAME=v4.0.0-$(date +'%Y.%m.%d')" >> $GITHUB_ENV | |
| # Create a new version tag | |
| - name: Create version tag | |
| run: | | |
| git config user.email "t8ddy.bot@gmail.com" | |
| git config user.name "t8ddy" | |
| # configure remote to use the secret token for pushing | |
| git remote set-url origin https://x-access-token:${{ secrets.T8DDY_TOKEN }}@github.com/${{ github.repository }} | |
| git tag "${{ env.VERSION_NAME }}" | |
| git push origin --tags |