Get version from git or VERSION file #5
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: Update VERSION file | |
on: | |
release: | |
types: [published] | |
# TODO: remove this | |
push: | |
branches: | |
- makaimann/cibuildwheel | |
jobs: | |
update-version: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get current release version | |
id: get_version | |
run: | | |
# Attempt to get the most recent tag | |
if ! VERSION=$(git describe --tags --abbrev=0 2>/dev/null); then | |
echo "Error: No tags found in the repository" | |
exit 1 | |
fi | |
# Validate that the version looks reasonable (optional) | |
if ! echo "$VERSION" | grep -qE '^v?[0-9]+\.[0-9]+\.[0-9]+'; then | |
echo "Warning: Tag '$VERSION' doesn't match expected version format" | |
fi | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Update VERSION file | |
run: | | |
echo -e "# This file is auto-generated by a GitHub Action -- do not edit\n${{ steps.get_version.outputs.version }}" > VERSION | |
- name: Commit and push if changed | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
git add VERSION | |
if git diff --staged --quiet; then | |
echo "No changes to commit" | |
exit 0 | |
fi | |
git commit -m "chore: Update VERSION file to ${{ steps.get_version.outputs.version }}" | |
git push |