Skip to content

Commit

Permalink
Merge pull request #11 from climatepolicyradar/refactor/naming-and-co…
Browse files Browse the repository at this point in the history
…de-quality-improvements

Refactor/naming and code quality improvements
  • Loading branch information
THOR300 authored Apr 25, 2024
2 parents 4370887 + cb67720 commit f3445f4
Show file tree
Hide file tree
Showing 9 changed files with 1,460 additions and 738 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
4 changes: 2 additions & 2 deletions .github/actions/precommit-checks/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ runs:

- shell: bash
run: |
pipx install poetry==1.3.2
pipx install poetry==1.8.2
- name: Install python or load from cache with dependencies
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "poetry"
cache: poetry

- shell: bash
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ runs:

- name: Install poetry
shell: bash
run: pipx install poetry==1.3.2
run: pipx install poetry==1.8.2

- name: Install python or load from cache with dependencies
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "poetry"
cache: poetry

- name: Install dependencies
shell: bash
Expand All @@ -30,7 +30,7 @@ runs:
- name: Install latest Vespa CLI
shell: bash
env:
VESPA_CLI_VERSION: "8.250.43"
VESPA_CLI_VERSION: 8.250.43
run: |
mkdir vespa-cli
curl -fsSL https://github.com/vespa-engine/vespa/releases/download/v${VESPA_CLI_VERSION}/vespa-cli_${VESPA_CLI_VERSION}_linux_amd64.tar.gz | \
Expand Down
62 changes: 34 additions & 28 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ on:
jobs:
precommit-checks:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Run pre-commit checks
uses: ./.github/actions/precommit-checks
- name: Run pre-commit checks
uses: ./.github/actions/precommit-checks

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

- name: Run fixme checks
uses: ./.github/actions/fixme-checks
- name: Run fixme checks
uses: ./.github/actions/fixme-checks

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

- name: Check the package version
uses: ./.github/actions/check-version
- name: Check the package version
uses: ./.github/actions/check-version

placeholder-version-checks:
runs-on: ubuntu-latest
Expand All @@ -44,13 +44,19 @@ jobs:

test:
runs-on: ubuntu-latest
needs: [precommit-checks, fixme-checks, package-version-checks, placeholder-version-checks]
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Run tests
uses: ./.github/actions/test
needs:
[
precommit-checks,
fixme-checks,
package-version-checks,
placeholder-version-checks,
]
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Run tests
uses: ./.github/actions/test

test-publish:
runs-on: ubuntu-latest
Expand All @@ -61,13 +67,13 @@ jobs:
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry==1.3.2
run: pipx install poetry==1.8.2

- name: Install python or load from cache with dependencies
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "poetry"
cache: poetry

- name: Install dependencies
run: |
Expand All @@ -79,11 +85,11 @@ jobs:
poetry version "1.0.${CURRENT_DATETIME}"
poetry version
- name: Build
- name: Build
run: |
poetry build
poetry build
- name: Publish
- name: Publish
run: |
poetry config repositories.test-pypi https://test.pypi.org/legacy/
poetry publish --username __token__ --password ${{ secrets.TEST_PYPI_TOKEN }} -r test-pypi
poetry publish --username __token__ --password ${{ secrets.TEST_PYPI_TOKEN }} -r test-pypi
66 changes: 36 additions & 30 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ on:
jobs:
precommit-checks:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Run pre-commit checks
uses: ./.github/actions/precommit-checks
- name: Run pre-commit checks
uses: ./.github/actions/precommit-checks

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

- name: Run fixme checks
uses: ./.github/actions/fixme-checks
- name: Run fixme checks
uses: ./.github/actions/fixme-checks

package-version-checks:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Run package version checks
uses: ./.github/actions/check-version-release
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Run package version checks
uses: ./.github/actions/check-version-release

placeholder-version-checks:
runs-on: ubuntu-latest
Expand All @@ -43,13 +43,19 @@ jobs:

test:
runs-on: ubuntu-latest
needs: [precommit-checks, fixme-checks, package-version-checks, placeholder-version-checks]
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Run tests
uses: ./.github/actions/test
needs:
[
precommit-checks,
fixme-checks,
package-version-checks,
placeholder-version-checks,
]
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Run tests
uses: ./.github/actions/test

publish:
runs-on: ubuntu-latest
Expand All @@ -60,27 +66,27 @@ jobs:
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry==1.7.1
run: pipx install poetry==1.8.2

- name: Install python or load from cache with dependencies
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "poetry"
cache: poetry

- name: Install dependencies
run: |
poetry install
- name: Update version in pyproject.toml
- name: Update version in pyproject.toml
run: |
PACKAGE_VERSION=$(python -c "from src import cpr_sdk; print(cpr_sdk.__version__)")
poetry version $PACKAGE_VERSION
poetry version $PACKAGE_VERSION
- name: Build
- name: Build
run: |
poetry build
poetry build
- name: Publish
- name: Publish
run: |
poetry publish --username __token__ --password ${{ secrets.PYPI_TOKEN }}
Loading

0 comments on commit f3445f4

Please sign in to comment.