Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: test built version #54

Merged
merged 46 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6ff042a
Fix pyproject.toml config
bonjourmauko Dec 20, 2022
aaa58c1
Generate lock
bonjourmauko Dec 20, 2022
69998e5
Ensure sync of deps
bonjourmauko Dec 20, 2022
b00f68e
Fix line warning
bonjourmauko Dec 20, 2022
fc805b4
Make tests pass
bonjourmauko Dec 20, 2022
d2de4d0
Use semver for dependencies
bonjourmauko Dec 21, 2022
317c218
Ignore .tox files
bonjourmauko Dec 21, 2022
9f1b9be
Add tox config
bonjourmauko Dec 21, 2022
03c6b2e
Fix pytest dependencies
bonjourmauko Dec 21, 2022
1c80b90
Let tox build the package
bonjourmauko Dec 21, 2022
3e6031d
Test in isolation
bonjourmauko Dec 21, 2022
84e2f89
Fix lint in ci
bonjourmauko Dec 21, 2022
31ca7ec
Fix tox env definition
bonjourmauko Dec 21, 2022
b471dd2
Fix workflow
bonjourmauko Dec 21, 2022
bfd85bd
Fix tox.ini
bonjourmauko Dec 21, 2022
8151f9a
Fix symbolic links visibility
bonjourmauko Dec 21, 2022
7b6a11e
Add test-api to tox
bonjourmauko Dec 21, 2022
fdcb1a2
Use poetry to run linters
bonjourmauko Dec 21, 2022
afd712e
Use poetry for build & publish
bonjourmauko Dec 21, 2022
eb57ea5
Run tasks with poetry
bonjourmauko Dec 21, 2022
9d6dcad
Update README
bonjourmauko Dec 21, 2022
988b986
Bump version
bonjourmauko Dec 21, 2022
98789ae
Do not ignore poetry.lock
bonjourmauko Dec 22, 2022
9c49ab7
Fix build
bonjourmauko Dec 22, 2022
1f6df83
Do not make build require build
bonjourmauko Dec 22, 2022
0966120
Add tox.ini to the cache
bonjourmauko Dec 22, 2022
1f39711
Fix linter
bonjourmauko Dec 22, 2022
2f8a953
Try to fix the test cache
bonjourmauko Dec 22, 2022
d38aaa0
Fix pip install in tox.ini
bonjourmauko Dec 22, 2022
38a5a3f
Add Makefile to the cache
bonjourmauko Dec 22, 2022
e9302dd
Update README.md
bonjourmauko Dec 22, 2022
29ea784
Simplify smoke test
bonjourmauko Dec 23, 2022
53a2be7
Merge branch 'master' into add-poetry
bonjourmauko Oct 16, 2024
125e138
chore: fix linting warnings
bonjourmauko Oct 16, 2024
33bf4e3
chore: type in README.md
bonjourmauko Oct 16, 2024
8e9089f
ci:add lint to tox
bonjourmauko Oct 16, 2024
a76e65d
ci: fix cache
bonjourmauko Oct 16, 2024
7d6dc5e
ci: fix poetry install
bonjourmauko Oct 16, 2024
fbf7165
ci: fix tox lint
bonjourmauko Oct 16, 2024
66d3d2e
build: add .yamllint
bonjourmauko Oct 16, 2024
86c2ec9
fix: package name
bonjourmauko Oct 18, 2024
99f6490
fix: poetry tasks
bonjourmauko Oct 18, 2024
22b4476
chore: update deps
bonjourmauko Oct 18, 2024
eb615ea
build: update lock
bonjourmauko Oct 18, 2024
3bd47e5
docs: add poetry
bonjourmauko Oct 18, 2024
2b92a88
style: format pyproject.toml
bonjourmauko Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/has-functional-changes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore .github/*"

last_tagged_commit=$(git describe --tags --abbrev=0 --first-parent) # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit
last_tagged_commit=$(git describe --tags --abbrev=0 --first-parent) # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit

if git diff-index --name-only --exit-code $last_tagged_commit -- . `echo " $IGNORE_DIFF_ON" | sed 's/ / :(exclude)/g'` # Check if any file that has not be listed in IGNORE_DIFF_ON has changed since the last tag was published.
then
echo "No functional changes detected."
exit 1
else echo "The functional files above were changed."
if git diff-index --name-only --exit-code $last_tagged_commit -- . $(echo " $IGNORE_DIFF_ON" | sed 's/ / :(exclude)/g'); then # Check if any file that has not be listed in IGNORE_DIFF_ON has changed since the last tag was published.
echo "No functional changes detected."
exit 1
else
echo "The functional files above were changed."
fi
14 changes: 5 additions & 9 deletions .github/is-version-number-acceptable.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
#! /usr/bin/env bash

if [[ ${GITHUB_REF#refs/heads/} == master ]]
then
if [[ ${GITHUB_REF#refs/heads/} == master ]]; then
echo "No need for a version check on master."
exit 0
fi

if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh
then
if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh; then
echo "No need for a version update."
exit 0
fi

current_version=$(python setup.py --version)
current_version=$(poetry version --short)

if git rev-parse --verify --quiet $current_version
then
if git rev-parse --verify --quiet $current_version; then
echo "Version $current_version already exists in commit:"
git --no-pager log -1 $current_version
echo
Expand All @@ -24,8 +21,7 @@ then
exit 1
fi

if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh | grep --quiet CHANGELOG.md
then
if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh | grep --quiet CHANGELOG.md; then
echo "CHANGELOG.md has not been modified, while functional changes were made."
echo "Explain what you changed before merging this branch into master."
echo "Look at the CONTRIBUTING.md file to learn how to write the changelog."
Expand Down
11 changes: 0 additions & 11 deletions .github/lint-changed-yaml-tests.sh

This file was deleted.

4 changes: 0 additions & 4 deletions .github/publish-git-tag.sh

This file was deleted.

14 changes: 0 additions & 14 deletions .github/test-api.sh

This file was deleted.

227 changes: 137 additions & 90 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,155 +2,202 @@ name: Extension-Template

on:
push:
branches: [ master ]
branches: [master]
pull_request:
types: [ assigned, opened, reopened, synchronize, ready_for_review ]
types: [assigned, opened, reopened, synchronize, ready_for_review]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.13 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any potentiel difference in patches between jobs will lead to a cache not found error.
- name: Cache build
id: restore-build

- name: Cache tests
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} # Cache the entire build Python environment
restore-keys: |
build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}
build-${{ env.pythonLocation }}-
- name: Build package
run: make build
- name: Cache release
id: restore-release
path: |
Makefile
openfisca_extension_template/tests
poetry.lock
pyproject.toml
key: tests-${{ github.sha }}

- name: Cache build
id: cache-build
uses: actions/cache@v4
with:
path: dist
key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
key: build-${{ hashFiles('poetry.lock') }}-${{ github.sha }}

- name: Install Poetry
run: pipx install poetry
bonjourmauko marked this conversation as resolved.
Show resolved Hide resolved

lint-files:
runs-on: ubuntu-22.04
needs: [ build ]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all the tags
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.13
- name: Cache build
id: restore-build
python-version: 3.9.20
cache: 'poetry'

- name: Install dependencies
run: make install

- name: Build package
if: steps.cache-build.outputs.cache-hit != 'true'
run: poetry build

lint:
runs-on: ubuntu-24.04
needs: [build]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Restore tests
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
- run: make check-syntax-errors
- run: make check-style
- name: Lint YAML tests
run: "${GITHUB_WORKSPACE}/.github/lint-changed-yaml-tests.sh"

test-yaml:
runs-on: ubuntu-22.04
needs: [ build ]
steps:
- uses: actions/checkout@v4
path: |
Makefile
openfisca_extension_template/tests
poetry.lock
pyproject.toml
key: tests-${{ github.sha }}

- name: Install Poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.13
- name: Cache build
id: restore-build
python-version: 3.9.20
cache: 'poetry'

- name: Lint files
run: make lint

test:
runs-on: ubuntu-24.04
needs: [build]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Restore tests
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
- run: openfisca test openfisca_extension_template/tests --country-package openfisca_country_template --extensions openfisca_extension_template
path: |
Makefile
openfisca_extension_template/tests
poetry.lock
pyproject.toml
key: tests-${{ github.sha }}

- name: Install Tox
run: pipx install tox

test-api:
runs-on: ubuntu-22.04
needs: [ build ]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.13
- name: Cache build
id: restore-build
python-version: 3.9.20

- name: Test files
run: tox -r -e py39

dist:
runs-on: ubuntu-24.04
needs: [build]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Restore tests
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
- name: Test the Web API
run: "${GITHUB_WORKSPACE}/.github/test-api.sh"
path: |
Makefile
openfisca_extension_template/tests
poetry.lock
pyproject.toml
key: tests-${{ github.sha }}

- name: Install Tox
run: pipx install tox

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.20

- name: Check built package
run: tox -r -e dist

check-version-and-changelog:
runs-on: ubuntu-22.04
needs: [ lint-files, test-yaml, test-api ] # Last job to run
needs: [lint, test, dist] # Last job to run

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all the tags
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.13

- name: Install Poetry
run: pipx install poetry

- name: Check version number has been properly updated
run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh"
run: ./.github/is-version-number-acceptable.sh

# GitHub Actions does not have a halt job option, to stop from deploying if no functional changes were found.
# We build a separate job to substitute the halt option.
# The `deploy` job is dependent on the output of the `check-for-functional-changes`job.
# GitHub Actions does not have a halt job option, to stop from deploying if
# no functional changes were found. We build a separate job to substitute the
# halt option. The `deploy` job is dependent on the output of the
# `check-for-functional-changes`job.
check-for-functional-changes:
runs-on: ubuntu-22.04
needs: [check-version-and-changelog]
if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch
needs: [ check-version-and-changelog ]

outputs:
status: ${{ steps.stop-early.outputs.status }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all the tags
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.13

- id: stop-early
run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi
run: if "./.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi

deploy:
runs-on: ubuntu-22.04
needs: [ check-for-functional-changes ]
needs: [check-for-functional-changes]
if: needs.check-for-functional-changes.outputs.status == 'success'

env:
PYPI_USERNAME: __token__
PYPI_PASSWORD: ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all the tags
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.13
- name: Cache build
id: restore-build
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
- name: Cache release
id: restore-release

- name: Install Poetry
run: pipx install poetry

- name: Restore build
uses: actions/cache@v4
with:
path: dist
key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
- name: Upload a Python package to PyPi
run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }}
key: build-${{ hashFiles('poetry.lock') }}-${{ github.sha }}

- name: Upload dist to PyPi
run: poetry publish --username $PYPI_USERNAME --password $PYPI_PASSWORD

- name: Publish a git tag
run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh"
run: |
git tag $(poetry version --short)
git push --tags # update the repository version
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
*.pyc
.idea
.python-version
.tox
build
dist
2 changes: 2 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
extends: relaxed
bonjourmauko marked this conversation as resolved.
Show resolved Hide resolved
Loading