Skip to content

Commit

Permalink
build: test built version (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko authored Oct 18, 2024
2 parents c2cd78d + 2b92a88 commit e232d82
Show file tree
Hide file tree
Showing 16 changed files with 2,230 additions and 223 deletions.
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

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
Loading

0 comments on commit e232d82

Please sign in to comment.