diff --git a/.github/workflows/build_upload_pypi_wheels.yml b/.github/workflows/build_upload_pypi_wheels.yml index e5893a472..aa8d6a660 100644 --- a/.github/workflows/build_upload_pypi_wheels.yml +++ b/.github/workflows/build_upload_pypi_wheels.yml @@ -33,8 +33,11 @@ jobs: fail-fast: false runs-on: ${{ matrix.os }} steps: - - name: Checkout project (for test files) + - name: Checkout project uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Setup Python ${{ matrix.python-version }} uses: actions/setup-python@v5 @@ -106,7 +109,9 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 # Ensure tags are fetched for versioning + fetch-depth: 0 + fetch-tags: true + - name: Create source distribution shell: bash -l {0} diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 2e74809ca..d668cbd1d 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -26,6 +26,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # Ensure tags are fetched for versioning + fetch-tags: true - uses: actions/setup-python@v5 with: python-version: | diff --git a/.github/workflows/set_version.yml b/.github/workflows/set_version.yml index 05f8f96c7..5bbf42c24 100644 --- a/.github/workflows/set_version.yml +++ b/.github/workflows/set_version.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: inputs: ref: - description: "Target branch, tag or SHA" + description: "Target branch" required: true type: string version: @@ -13,15 +13,22 @@ on: type: string jobs: - show-branch: + set-version: runs-on: ubuntu-latest steps: - - name: Show input parameters - shell: bash -l {0} - run: | - echo "${{ inputs.ref }}" - echo "${{ inputs.version }}" + - name: Validate and normalise version number + shell: python + run : | + import os + from packaging.version import Version + + version_string = 'v' + str(Version("${{ inputs.version }}")) + + print(f"Normalised version string: {version_string}") + + with open(os.environ["GITHUB_ENV"], "a") as github_env: + print(f"VERSION_STRING={version_string}", file=github_env) - uses: actions/checkout@v4 with: @@ -29,12 +36,51 @@ jobs: fetch-tags: true fetch-depth: 0 - - name: "Tag locally" + - name: "Update version.py" shell: bash -l {0} run: | - git tag ${{ inputs.version }} + echo "__version__ = \"${VERSION_STRING}\"" > euphonic/version.py + cat euphonic/version.py + + - name: "Update CITATION.cff" + shell: bash -l {0} + run: | + sed -i "s/^version:\ .*/version: ${VERSION_STRING}/" CITATION.cff + sed -i "s/^date-released:\ .*/date-released: $(date -I)/" CITATION.cff + + - name: "Create commit" + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add euphonic/version.py CITATION.cff + + if git diff --cached --quiet + then + echo "No files were changed, skipping commit" + else + git commit -m "Set version number" + fi + + - name: "Tag commit" + shell: bash -l {0} + run: | + if test $(git describe --tags --exact-match) = $VERSION_STRING + then + echo "The correct tag is already on this commit" + else + git tag $VERSION_STRING + fi - name: "Show updated log" + run: | + git log --pretty=oneline --abbrev-commit --decorate | head -n 5 + git diff HEAD^ + + - name: "Push commit to branch" shell: bash -l {0} run: | - git log --pretty=oneline --abbrev-commit --decorate | head + # Verify that ref is a branch (as opposed to a tag or hash) + git show-ref --verify "refs/heads/${{ inputs.ref }}" + + git push origin ${{ inputs.ref }} + git push origin tag $VERSION_STRING diff --git a/CITATION.cff b/CITATION.cff index 0ebf37255..48038b25b 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -33,8 +33,8 @@ authors: given-names: "Jacob S." title: "Euphonic" doi: 10.5286/SOFTWARE/EUPHONIC -version: 1.4.0 -date-released: 2024-01-30 +version: v1.4.0.post1 +date-released: 2024-12-12 license: GPL-3.0-only repository-code: https://github.com/pace-neutrons/Euphonic url: https://euphonic.readthedocs.io diff --git a/euphonic/version.py b/euphonic/version.py index c1a634494..e39efe4bf 100644 --- a/euphonic/version.py +++ b/euphonic/version.py @@ -1 +1 @@ -__version__ = "v1.4.0" +__version__ = "v1.4.0.post1"