Skip to content

Commit

Permalink
Adding a test for the placeholder version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark committed Apr 22, 2024
1 parent 96ce0a4 commit 8f8d033
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 22 deletions.
18 changes: 9 additions & 9 deletions .github/actions/check-version-release/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: check-pyproject-version
description: Check that the pyproject.toml version is the same as the latest GitHub release
name: check-package-attribute-version
description: Check that the package version attribute defined version is the same as the latest GitHub release.

runs:
using: composite
Expand All @@ -15,22 +15,22 @@ runs:
- shell: bash
run: |
pip install packaging==24.0
PYPROJECT_VERSION=$(python -c "from src import cpr_sdk; print(cpr_sdk.__version__)")
echo "PYPROJECT_VERSION=${PYPROJECT_VERSION}"
PACKAGE_ATTRIBUTE_VERSION=$(python -c "from src import cpr_sdk; print(cpr_sdk.__version__)")
echo "PACKAGE_ATTRIBUTE_VERSION=${PACKAGE_ATTRIBUTE_VERSION}"
GITHUB_RELEASE_VERSION=$(curl --silent "https://api.github.com/repos/climatepolicyradar/cpr-sdk/releases/latest" | jq -r '.tag_name')
# remove the "v" from the version
GITHUB_RELEASE_VERSION=${GITHUB_RELEASE_VERSION#v}
echo "GITHUB_RELEASE_VERSION=${GITHUB_RELEASE_VERSION}"
# Check that semver tag is equal to the github release version
PYPROJECT_EQUALS_GITHUB_RELEASE=$(python -c "from packaging.version import Version; print(Version('${PYPROJECT_VERSION}') == Version('${GITHUB_RELEASE_VERSION}'))")
echo "PYPROJECT_EQUALS_GITHUB_RELEASE=${PYPROJECT_EQUALS_GITHUB_RELEASE}"
PACKAGE_ATTRIBUTE_EQUALS_GITHUB_RELEASE=$(python -c "from packaging.version import Version; print(Version('${PACKAGE_ATTRIBUTE_VERSION}') == Version('${GITHUB_RELEASE_VERSION}'))")
echo "PACKAGE_ATTRIBUTE_EQUALS_GITHUB_RELEASE=${PACKAGE_ATTRIBUTE_EQUALS_GITHUB_RELEASE}"
if [[ "$PYPROJECT_EQUALS_GITHUB_RELEASE" == True ]]; then
echo "The pyproject.toml version is equal to the latest GitHub release."
if [[ "$PACKAGE_ATTRIBUTE_EQUALS_GITHUB_RELEASE" == True ]]; then
echo "The cpr_sdk.__version__ version is equal to the latest GitHub release."
else
echo "The pyproject.toml version is NOT equal to the the latest GitHub release."
echo "The cpr_sdk.__version__ version is NOT equal to the the latest GitHub release."
exit 1
fi
18 changes: 9 additions & 9 deletions .github/actions/check-version/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: check-pyproject-version
description: Check that the pyproject.toml version is greater than the latest GitHub release
name: check-package-attribute-version
description: Check that the package attribute version is greater than the latest GitHub release

runs:
using: composite
Expand All @@ -15,21 +15,21 @@ runs:
- shell: bash
run: |
pip install packaging==24.0
PYPROJECT_VERSION=$(python -c "from src import cpr_sdk; print(cpr_sdk.__version__)")
echo "PYPROJECT_VERSION=${PYPROJECT_VERSION}"
PACKAGE_ATTRIBUTE_VERSION=$(python -c "from src import cpr_sdk; print(cpr_sdk.__version__)")
echo "PACKAGE_ATTRIBUTE_VERSION=${PACKAGE_ATTRIBUTE_VERSION}"
GITHUB_RELEASE_VERSION=$(curl --silent "https://api.github.com/repos/climatepolicyradar/cpr-sdk/releases/latest" | jq -r '.tag_name')
# remove the "v" from the version
GITHUB_RELEASE_VERSION=${GITHUB_RELEASE_VERSION#v}
echo "GITHUB_RELEASE_VERSION=${GITHUB_RELEASE_VERSION}"
# Check that semver tag is greater than the github release version
PYPROJECT_GREATER_THAN_GITHUB_RELEASE=$(python -c "from packaging.version import Version; print(Version('${PYPROJECT_VERSION}') > Version('${GITHUB_RELEASE_VERSION}'))")
echo "PYPROJECT_GREATER_THAN_GITHUB_RELEASE=${PYPROJECT_GREATER_THAN_GITHUB_RELEASE}"
PACKAGE_ATTRIBUTE_GREATER_THAN_GITHUB_RELEASE=$(python -c "from packaging.version import Version; print(Version('${PACKAGE_ATTRIBUTE_VERSION}') > Version('${GITHUB_RELEASE_VERSION}'))")
echo "PACKAGE_ATTRIBUTE_GREATER_THAN_GITHUB_RELEASE=${PACKAGE_ATTRIBUTE_GREATER_THAN_GITHUB_RELEASE}"
if [[ "$PYPROJECT_GREATER_THAN_GITHUB_RELEASE" == True ]]; then
echo "The pyproject.toml version is greater than the latest GitHub release."
if [[ "$PACKAGE_ATTRIBUTE_GREATER_THAN_GITHUB_RELEASE" == True ]]; then
echo "The cpr_sdk.__init__ version is greater than the latest GitHub release."
else
echo "The pyproject.toml version is not greater than the latest GitHub release."
echo "The cpr_sdk.__init__ version is not greater than the latest GitHub release."
exit 1
fi
25 changes: 25 additions & 0 deletions .github/actions/placeholder/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: check-placeholder-version
description: Check that the placeholder version in the pyproject.toml is 0.0.0

runs:
using: composite
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- shell: bash
run: |
echo "PYPROJECT_VERSION=$(poetry version --short)"
if [[ "$PYPROJECT_VERSION" == "0.0.0" ]]; then
echo "The pyproject.toml version is the correct placeholder version."
else
echo "The pyproject.toml version is NOT the correct placeholder version"
exit 1
fi
13 changes: 11 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@ jobs:
- name: Check the package version
uses: ./.github/actions/check-version

placeholder-version-checks:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Check the placeholder version
uses: ./.github/actions/placeholder

test:
runs-on: ubuntu-latest
needs: [precommit-checks, fixme-checks, package-version-checks]
needs: [precommit-checks, fixme-checks, package-version-checks, placeholder-version-checks]
steps:
- name: Check out repository code
uses: actions/checkout@v4
Expand All @@ -58,7 +67,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "poetry"
cache: poetry

- name: Install dependencies
run: |
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,18 @@ jobs:
- name: Run package version checks
uses: ./.github/actions/check-version-release

placeholder-version-checks:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Check the placeholder version
uses: ./.github/actions/placeholder

test:
runs-on: ubuntu-latest
needs: [precommit-checks, fixme-checks, package-version-checks]
needs: [precommit-checks, fixme-checks, package-version-checks, placeholder-version-checks]
steps:
- name: Check out repository code
uses: actions/checkout@v4
Expand All @@ -57,7 +66,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "poetry"
cache: poetry

- name: Install dependencies
run: |
Expand Down

0 comments on commit 8f8d033

Please sign in to comment.