From 25f6f8522be73e7c63926932c8f4c2b170341ef5 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 24 Apr 2024 15:00:49 +0200 Subject: [PATCH 01/40] Allow to bypass steps on CI with `CI` env variable --- bootstrap.sh | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 31ef96a..712a5ca 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -12,7 +12,7 @@ if [[ $JURISDICTION_NAME ]] && [[ $REPOSITORY_URL ]] then continue=Y fi -if [[ -d .git ]] +if [[ $CI ]] && [ ! -d .git ] then echo 'It seems you cloned this repository, or already initialised it.' echo 'Refusing to go further as you might lose work.' @@ -62,17 +62,20 @@ last_changelog_number=$(grep --line-number '^# Example Entry' CHANGELOG.md | cut first_commit_message='Initial import from OpenFisca country-template' second_commit_message='Customise country-template through script' -echo -cd .. -mv $parent_folder openfisca-$NO_SPACES_JURISDICTION_LABEL -cd openfisca-$NO_SPACES_JURISDICTION_LABEL +if [[ ! "$CI" ]] +then + echo + cd .. + mv $parent_folder openfisca-$NO_SPACES_JURISDICTION_LABEL + cd openfisca-$NO_SPACES_JURISDICTION_LABEL -echo -e "${PURPLE}* ${PURPLE}Initialise git repository\033[0m" -git init --initial-branch=main > /dev/null 2>&1 -git add . + echo -e "${PURPLE}* ${PURPLE}Initialise git repository\033[0m" + git init --initial-branch=main > /dev/null 2>&1 + git add . -git commit --no-gpg-sign --message "$first_commit_message" --author='OpenFisca Bot ' --quiet -echo -e "${PURPLE}* ${PURPLE}Initial git commit made to 'main' branch: '\033[0m${BLUE}$first_commit_message\033[0m${PURPLE}'\033[0m" + git commit --no-gpg-sign --message "$first_commit_message" --author='OpenFisca Bot ' --quiet + echo -e "${PURPLE}* ${PURPLE}Initial git commit made to 'main' branch: '\033[0m${BLUE}$first_commit_message\033[0m${PURPLE}'\033[0m" +fi all_module_files=`find openfisca_country_template -type f ! -name "*.DS_Store"` echo -e "${PURPLE}* ${PURPLE}Replace default country_template references\033[0m" @@ -102,6 +105,12 @@ git mv openfisca_country_template $package_name echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}bootstrap.sh\033[0m${PURPLE} script\033[0m" git rm bootstrap.sh > /dev/null 2>&1 + +if [[ $CI ]] +then + exit 0 +fi + git add . git commit --no-gpg-sign --message "$second_commit_message" --author='OpenFisca Bot ' --quiet From c29c9036e85b8d4cd17bde8f009a71e149de9576 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 24 Apr 2024 15:04:08 +0200 Subject: [PATCH 02/40] Avoid modifying main workflow in bootstrap script --- .github/workflows/workflow.yml | 4 ++-- bootstrap.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f156710..f105400 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,4 +1,4 @@ -name: Country-Template +name: CI/CD Pipeline on: push: @@ -74,7 +74,7 @@ jobs: with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - run: openfisca test --country-package openfisca_country_template openfisca_country_template/tests + - run: make test test-api: runs-on: ubuntu-20.04 diff --git a/bootstrap.sh b/bootstrap.sh index 712a5ca..e65a1b2 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -81,8 +81,8 @@ all_module_files=`find openfisca_country_template -type f ! -name "*.DS_Store"` echo -e "${PURPLE}* ${PURPLE}Replace default country_template references\033[0m" # Use intermediate backup files (`-i`) with a weird syntax due to lack of portable 'no backup' option. See https://stackoverflow.com/q/5694228/594053. sed -i.template "s|openfisca-country_template|openfisca-$NO_SPACES_JURISDICTION_LABEL|g" README.md Makefile pyproject.toml CONTRIBUTING.md -sed -i.template "s|country_template|$SNAKE_CASE_JURISDICTION|g" README.md pyproject.toml .flake8 .github/workflows/workflow.yml Makefile MANIFEST.in $all_module_files -sed -i.template "s|Country-Template|$JURISDICTION_NAME|g" README.md pyproject.toml .github/workflows/workflow.yml .github/PULL_REQUEST_TEMPLATE.md CONTRIBUTING.md +sed -i.template "s|country_template|$SNAKE_CASE_JURISDICTION|g" README.md pyproject.toml .flake8 Makefile MANIFEST.in $all_module_files +sed -i.template "s|Country-Template|$JURISDICTION_NAME|g" README.md pyproject.toml .github/PULL_REQUEST_TEMPLATE.md CONTRIBUTING.md echo -e "${PURPLE}* ${PURPLE}Remove bootstrap instructions\033[0m" sed -i.template -e "3,${last_bootstrapping_line_number}d" README.md # remove instructions lines From 5f54fae1f2e47161ed35e53d8d3154e4921b9d5e Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 24 Apr 2024 15:10:32 +0200 Subject: [PATCH 03/40] Perform bootstrapping when used as GitHub template --- .github/workflows/bootstrap.yml | 31 +++++++++++++++++++++++++++++++ .github/workflows/workflow.yml | 2 +- bootstrap.sh | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/bootstrap.yml diff --git a/.github/workflows/bootstrap.yml b/.github/workflows/bootstrap.yml new file mode 100644 index 0000000..3d2c4af --- /dev/null +++ b/.github/workflows/bootstrap.yml @@ -0,0 +1,31 @@ +name: Bootstrap + +on: + create: + +permissions: + actions: write + checks: write + contents: write + +jobs: + bootstrap: + # Ensure this job does not run on the template repository or when the repository is forked + if: ${{ !github.event.repository.is_template && !github.event.repository.fork }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Execute the bootstrap script + run: CI=true JURISDICTION_NAME="$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//')" REPOSITORY_URL="${{ github.repositoryUrl }}" ./bootstrap.sh + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "Adapt template automatically" + tagging_message: "0.0.1" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f105400..164a454 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,4 +1,4 @@ -name: CI/CD Pipeline +name: CI and CD Pipeline on: push: diff --git a/bootstrap.sh b/bootstrap.sh index e65a1b2..1b29b9f 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -106,6 +106,9 @@ git mv openfisca_country_template $package_name echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}bootstrap.sh\033[0m${PURPLE} script\033[0m" git rm bootstrap.sh > /dev/null 2>&1 +echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}bootstrap.yml\033[0m${PURPLE} GitHub Action\033[0m" +rm -f .github/workflows/bootstrap.yml + if [[ $CI ]] then exit 0 From 176574b8acca5841e948fc60ea5c62c6dcd8cee1 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 24 Apr 2024 15:27:39 +0200 Subject: [PATCH 04/40] Use a less technical naming for better accessibility --- .github/workflows/{bootstrap.yml => first-time-setup.yml} | 8 ++++---- bootstrap.sh => first-time-setup.sh | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) rename .github/workflows/{bootstrap.yml => first-time-setup.yml} (85%) rename bootstrap.sh => first-time-setup.sh (95%) diff --git a/.github/workflows/bootstrap.yml b/.github/workflows/first-time-setup.yml similarity index 85% rename from .github/workflows/bootstrap.yml rename to .github/workflows/first-time-setup.yml index 3d2c4af..141e57d 100644 --- a/.github/workflows/bootstrap.yml +++ b/.github/workflows/first-time-setup.yml @@ -1,4 +1,4 @@ -name: Bootstrap +name: First time setup on: create: @@ -9,7 +9,7 @@ permissions: contents: write jobs: - bootstrap: + first-time-setup: # Ensure this job does not run on the template repository or when the repository is forked if: ${{ !github.event.repository.is_template && !github.event.repository.fork }} runs-on: ubuntu-latest @@ -19,8 +19,8 @@ jobs: with: repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Execute the bootstrap script - run: CI=true JURISDICTION_NAME="$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//')" REPOSITORY_URL="${{ github.repositoryUrl }}" ./bootstrap.sh + - name: Execute the first-time-setup script + run: CI=true JURISDICTION_NAME="$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//')" REPOSITORY_URL="${{ github.repositoryUrl }}" ./first-time-setup.sh - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 diff --git a/bootstrap.sh b/first-time-setup.sh similarity index 95% rename from bootstrap.sh rename to first-time-setup.sh index 1b29b9f..8f58de7 100755 --- a/bootstrap.sh +++ b/first-time-setup.sh @@ -103,11 +103,11 @@ find . -name "*.template" -type f -delete echo -e "${PURPLE}* ${PURPLE}Rename package to: \033[0m${BLUE}$package_name\033[0m" git mv openfisca_country_template $package_name -echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}bootstrap.sh\033[0m${PURPLE} script\033[0m" -git rm bootstrap.sh > /dev/null 2>&1 +echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.sh\033[0m${PURPLE} script\033[0m" +git rm first-time-setup.sh > /dev/null 2>&1 -echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}bootstrap.yml\033[0m${PURPLE} GitHub Action\033[0m" -rm -f .github/workflows/bootstrap.yml +echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.yml\033[0m${PURPLE} GitHub Action\033[0m" +rm -f .github/workflows/first-time-setup.yml if [[ $CI ]] then From 668beab90d49028f11b81d401d3c88a64010180b Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 24 Apr 2024 15:11:34 +0200 Subject: [PATCH 05/40] Update documentation --- README.md | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c675bbf..ff9333b 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,37 @@ # OpenFisca Country-Template -This repository helps you quickly bootstrap and use your own OpenFisca country package. +This repository helps you quickly set up and use your own OpenFisca country package. -**You should NOT fork it but [download a copy](https://github.com/openfisca/country-template/archive/master.zip) of it** and follow the bootstrapping instructions below. +**You should NOT fork it** but follow the set up instructions below. > Otherwise, you will have to clean up all tags when you deploy your own country package. -## Bootstrapping your Country Package +## Setting up your Country Package This set of instructions **only needs to be followed once** and will create your own copy of this boilerplate directory, customising it to the country you want to work on. You will need to have [Git](https://git-scm.com) installed. -1. [Download a copy](https://github.com/openfisca/country-template/archive/master.zip) of this repository, unzip it and `cd` into it in a Terminal window. +### Using GitHub (recommended for GitHub users) + +1. Click on the “Use this template” dropdown and select “Create a new repository” -2. Create a new repository on your favourite git host (Github, Bitbucket, GitLab, etc) with the name openfisca-your_country_name. For example, `openfisca-new_zealand` or `openfisca-france`. +2. Set the repository name to `openfisca-`. For example, `openfisca-new_zealand` or `openfisca-france`. -3. Execute the `bootstrap.sh` script to initialise the git repository. This performs numerous tasks including replacing all references to `openfisca-country_template` with references to the new country package. - - To execute the script run `bash bootstrap.sh` from the command line. _Note: this script can only run on Unix systems, but OpenFisca and the resulting package will work on Windows too._ - - After the `bootstrap.sh` has run both it and these instructions are removed. +3. Wait a minute or two for the automatic setup to run after being redirected to the newly generated repository. Once done, the title of the readme should be `OpenFisca `. 4. Follow the instructions in the new repository's README.md. +### Manual setup (recommended for users of other Git hosts) + +1. [Download a copy](https://github.com/openfisca/country-template/archive/master.zip) of this repository, unzip it and `cd` into it in a Terminal window. + +2. Create a new repository on your favourite git host (Bitbucket, GitLab, …) with the name `openfisca-`. For example, `openfisca-new_zealand` or `openfisca-france`. + +3. Execute the `first-time-setup.sh` script to initialise the git repository. This performs numerous tasks including replacing all references to `openfisca-country_template` with references to the new country package. + - To execute the script run `bash first-time-setup.sh` from the command line + - After the `first-time-setup.sh` has run both it and these instructions are removed. + +4. Follow the instructions in the new repository's `README.md.` + ## Writing the Legislation The country whose law is modelled here has a very simple tax and benefit system. From 00260ce156e686437866d62f0059e45139bbb86b Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 11:45:56 +0200 Subject: [PATCH 06/40] Unify commit message with first-time-setup script --- .github/workflows/first-time-setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/first-time-setup.yml b/.github/workflows/first-time-setup.yml index 141e57d..d18fbf2 100644 --- a/.github/workflows/first-time-setup.yml +++ b/.github/workflows/first-time-setup.yml @@ -25,7 +25,7 @@ jobs: - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 with: - commit_message: "Adapt template automatically" + commit_message: "Customise country-template through CI" tagging_message: "0.0.1" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 4361f2a5e2484fc953bd7c97b7516122b622fbed Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 11:04:42 +0200 Subject: [PATCH 07/40] Decompose monolithic workflow into specialized workflows --- .github/workflows/build.yml | 33 +++++++ .github/workflows/deploy.yml | 63 +++++++++++++ .github/workflows/validate.yml | 85 +++++++++++++++++ .github/workflows/workflow.yml | 161 --------------------------------- 4 files changed, 181 insertions(+), 161 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/validate.yml delete mode 100644 .github/workflows/workflow.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..633e343 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,33 @@ +name: Build + +on: + workflow_call: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 # 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 + uses: actions/cache@v2 + 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 + uses: actions/cache@v2 + with: + path: dist + key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..65fb0d3 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,63 @@ +name: Deploy + +on: + pull_request_target: + branches: + - main + types: [ closed ] + + +jobs: + validate: + uses: "./.github/workflows/validate.yml" + + # 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-20.04 + if: github.ref == 'refs/heads/main' # Only triggered for the `main` branch + outputs: + status: ${{ steps.stop-early.outputs.status }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 + - id: stop-early + run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi + + deploy: + runs-on: ubuntu-20.04 + needs: [ validate, check-for-functional-changes ] + if: github.event.pull_request.merged == true && needs.check-for-functional-changes.outputs.status == 'success' + env: + PYPI_USERNAME: openfisca-bot + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} + - name: Cache release + id: restore-release + uses: actions/cache@v2 + with: + path: dist + key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} + - name: Upload a Python package to PyPi + run: twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD + - name: Publish a git tag + run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..1c31468 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,85 @@ +name: Validate + +on: + pull_request: + types: [ assigned, opened, reopened, synchronize, ready_for_review ] + workflow_dispatch: + workflow_call: + + +jobs: + build: + uses: "./.github/workflows/build.yml" + + lint-files: + runs-on: ubuntu-20.04 + needs: [ build ] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} + - run: make check-syntax-errors + - run: make check-style + - name: Lint Python files + run: "${GITHUB_WORKSPACE}/.github/lint-changed-python-files.sh" + - name: Lint YAML tests + run: "${GITHUB_WORKSPACE}/.github/lint-changed-yaml-tests.sh" + + test-yaml: + runs-on: ubuntu-20.04 + needs: [ build ] + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} + - run: make test + + test-api: + runs-on: ubuntu-20.04 + needs: [ build ] + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + 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" + + check-version-and-changelog: + runs-on: ubuntu-20.04 + needs: [ lint-files, test-yaml, test-api ] # Last job to run + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 + - name: Check version number has been properly updated + run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml deleted file mode 100644 index 164a454..0000000 --- a/.github/workflows/workflow.yml +++ /dev/null @@ -1,161 +0,0 @@ -name: CI and CD Pipeline - -on: - push: - branches: [ main ] - pull_request: - types: [ assigned, opened, reopened, synchronize, ready_for_review ] - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-20.04 - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 # 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 - uses: actions/cache@v2 - 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 - uses: actions/cache@v2 - with: - path: dist - key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - lint-files: - runs-on: ubuntu-20.04 - needs: [ build ] - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all the tags - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 - - name: Cache build - id: restore-build - uses: actions/cache@v2 - with: - path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - run: make check-syntax-errors - - run: make check-style - - name: Lint Python files - run: "${GITHUB_WORKSPACE}/.github/lint-changed-python-files.sh" - - name: Lint YAML tests - run: "${GITHUB_WORKSPACE}/.github/lint-changed-yaml-tests.sh" - - test-yaml: - runs-on: ubuntu-20.04 - needs: [ build ] - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 - - name: Cache build - id: restore-build - uses: actions/cache@v2 - with: - path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - run: make test - - test-api: - runs-on: ubuntu-20.04 - needs: [ build ] - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 - - name: Cache build - id: restore-build - uses: actions/cache@v2 - 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" - - check-version-and-changelog: - runs-on: ubuntu-20.04 - needs: [ lint-files, test-yaml, test-api ] # Last job to run - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all the tags - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 - - name: Check version number has been properly updated - run: "${GITHUB_WORKSPACE}/.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. - check-for-functional-changes: - runs-on: ubuntu-20.04 - if: github.ref == 'refs/heads/main' # Only triggered for the `main` branch - needs: [ check-version-and-changelog ] - outputs: - status: ${{ steps.stop-early.outputs.status }} - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all the tags - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 - - id: stop-early - run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi - - deploy: - runs-on: ubuntu-20.04 - needs: [ check-for-functional-changes ] - if: needs.check-for-functional-changes.outputs.status == 'success' - env: - PYPI_USERNAME: openfisca-bot - PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all the tags - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 - - name: Cache build - id: restore-build - uses: actions/cache@v2 - with: - path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - name: Cache release - id: restore-release - uses: actions/cache@v2 - with: - path: dist - key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - name: Upload a Python package to PyPi - run: twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD - - name: Publish a git tag - run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" From a6d1175cb98c0570b653f7d339ca018d2ccf4342 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 11:07:37 +0200 Subject: [PATCH 08/40] Remove obsolete dependency --- .github/workflows/validate.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 1c31468..f45c2bb 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -72,7 +72,6 @@ jobs: check-version-and-changelog: runs-on: ubuntu-20.04 - needs: [ lint-files, test-yaml, test-api ] # Last job to run steps: - uses: actions/checkout@v2 with: From 24d6c036f44dc115a9c190bf1eb5b1b5aa9d864f Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 11:12:22 +0200 Subject: [PATCH 09/40] Update job condition --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 65fb0d3..2add4be 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,7 +16,7 @@ jobs: # The `deploy` job is dependent on the output of the `check-for-functional-changes`job. check-for-functional-changes: runs-on: ubuntu-20.04 - if: github.ref == 'refs/heads/main' # Only triggered for the `main` branch + if: github.event.pull_request.merged == true outputs: status: ${{ steps.stop-early.outputs.status }} steps: From 721d53fdda8306e983732620e6d03f855c1addfe Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 14:30:00 +0200 Subject: [PATCH 10/40] Add changelog entry --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbee3e0..b3f48c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## 7.1.0 [#143](https://github.com/openfisca/country-template/pull/143) + +* Technical improvement +* Minor change +* Details: + - Automate template setup process via CI for GitHub users: + - When creating a new repository by using this template on GitHub, the setup script is automatically executed by the CI on the resulting generated repository. + - Improve accessibility by adopting less technical terminology: + - Replaced "bootstrap" with "first-time setup," clarifying its purpose as a one-time project initialization, particularly useful for users unfamiliar with the technical vocabulary. + - Decompose GitHub Actions monolithic workflow into specialized workflows: + - Split the `Country-Template` workflow into three distinct workflows: `build`, `validate` and `deploy` enhancing clarity and organization. + - Enhance accuracy of workflow triggers: + - Trigger deployment exclusively when a PR is merged on the `main` branch + - Trigger validation on PR events or as a dependency of the deployment workflow + + ## 7.0.0 [#139](https://github.com/openfisca/country-template/pull/139) * Technical improvement From ee2baedca5c84c046aae67b63022acd632fd76f9 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 14:30:10 +0200 Subject: [PATCH 11/40] Update version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 47445df..6ba3c09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openfisca-country_template" -version = "7.0.0" +version = "7.1.0" description = "OpenFisca Rules as Code model for Country-Template." readme = "README.md" keywords = ["microsimulation", "tax", "benefit", "rac", "rules-as-code"] From 90a7d70c789b9750387f9bc10b0e0e7d483bc701 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 14:34:52 +0200 Subject: [PATCH 12/40] Improve documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ff9333b..3c251ff 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,11 @@ This set of instructions **only needs to be followed once** and will create your ### Using GitHub (recommended for GitHub users) -1. Click on the “Use this template” dropdown and select “Create a new repository” +1. Click on the [“Use this template” dropdown and select “Create a new repository”](https://github.com/new?template_name=country-template&template_owner=openfisca). 2. Set the repository name to `openfisca-`. For example, `openfisca-new_zealand` or `openfisca-france`. -3. Wait a minute or two for the automatic setup to run after being redirected to the newly generated repository. Once done, the title of the readme should be `OpenFisca `. +3. Wait a moment for the automatic setup to run after being redirected to the newly generated repository. Once done, the title of the readme should be `OpenFisca `. 4. Follow the instructions in the new repository's README.md. From 63977180fd341a1c436121aec1870b61098a4dc7 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 14:54:40 +0200 Subject: [PATCH 13/40] Title case the jurisdiction name --- .github/workflows/first-time-setup.yml | 6 +++++- README.md | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/first-time-setup.yml b/.github/workflows/first-time-setup.yml index d18fbf2..caf6bbf 100644 --- a/.github/workflows/first-time-setup.yml +++ b/.github/workflows/first-time-setup.yml @@ -19,8 +19,12 @@ jobs: with: repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Set environment variables + run: | + echo "TITLE_CASE_JURISDICTION_NAME=$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//' | sed 's/[-|_]/ /g' | awk '{for (i=1; i<=NF; i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1')" >> $GITHUB_ENV + - name: Execute the first-time-setup script - run: CI=true JURISDICTION_NAME="$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//')" REPOSITORY_URL="${{ github.repositoryUrl }}" ./first-time-setup.sh + run: CI=true JURISDICTION_NAME="$TITLE_CASE_JURISDICTION_NAME" REPOSITORY_URL="${{ github.repositoryUrl }}" ./first-time-setup.sh - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 diff --git a/README.md b/README.md index 3c251ff..aad42ad 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This set of instructions **only needs to be followed once** and will create your 1. Click on the [“Use this template” dropdown and select “Create a new repository”](https://github.com/new?template_name=country-template&template_owner=openfisca). -2. Set the repository name to `openfisca-`. For example, `openfisca-new_zealand` or `openfisca-france`. +2. Set the repository name to `openfisca-`; use underscore `_` or dash `-` as separators. For example, `openfisca-new_zealand`, `openfisca-new-zealand` or `openfisca-france`. 3. Wait a moment for the automatic setup to run after being redirected to the newly generated repository. Once done, the title of the readme should be `OpenFisca `. From 7b3e90ffcbf7be3f0f051987e9bf2d0a866c04c8 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 15:08:31 +0200 Subject: [PATCH 14/40] Allow to manually trigger first time setup workflow --- .github/workflows/first-time-setup.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/first-time-setup.yml b/.github/workflows/first-time-setup.yml index caf6bbf..9512ff4 100644 --- a/.github/workflows/first-time-setup.yml +++ b/.github/workflows/first-time-setup.yml @@ -2,6 +2,7 @@ name: First time setup on: create: + workflow_dispatch: permissions: actions: write From de9206f3258db306bfbec486b886897179c2af20 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 15:20:27 +0200 Subject: [PATCH 15/40] Improve documentation --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aad42ad..ee718d2 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,12 @@ This set of instructions **only needs to be followed once** and will create your 2. Set the repository name to `openfisca-`; use underscore `_` or dash `-` as separators. For example, `openfisca-new_zealand`, `openfisca-new-zealand` or `openfisca-france`. -3. Wait a moment for the automatic setup to run after being redirected to the newly generated repository. Once done, the title of the readme should be `OpenFisca `. +3. After being redirected to your newly created repository, please allow a short period for the automatic setup to be executed. Once done, the title of the readme should be updated to `OpenFisca `. + +> If the automatic setup does not start within a few minutes, you can initiate it manually: +> - Navigate to the “Actions” tab. +> - Select the “First time setup” workflow. +> - Click on “Run workflow” to start the setup process manually. 4. Follow the instructions in the new repository's README.md. @@ -26,7 +31,7 @@ This set of instructions **only needs to be followed once** and will create your 2. Create a new repository on your favourite git host (Bitbucket, GitLab, …) with the name `openfisca-`. For example, `openfisca-new_zealand` or `openfisca-france`. -3. Execute the `first-time-setup.sh` script to initialise the git repository. This performs numerous tasks including replacing all references to `openfisca-country_template` with references to the new country package. +3. Execute the `first-time-setup.sh` script to initialise the git repository. This performs numerous tasks including replacing all references to `openfisca-country_template` with references to the new country package. - To execute the script run `bash first-time-setup.sh` from the command line - After the `first-time-setup.sh` has run both it and these instructions are removed. From e1924a873c394d83a646af63f13a832b65c45dfb Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 15:32:45 +0200 Subject: [PATCH 16/40] Remove spaces --- .github/workflows/deploy.yml | 1 - .github/workflows/validate.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2add4be..10dac37 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -6,7 +6,6 @@ on: - main types: [ closed ] - jobs: validate: uses: "./.github/workflows/validate.yml" diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index f45c2bb..715b09e 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -6,7 +6,6 @@ on: workflow_dispatch: workflow_call: - jobs: build: uses: "./.github/workflows/build.yml" From fd141ad58813a361ca33cf21569f85e4157dc7c4 Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Mon, 29 Apr 2024 14:57:20 +0200 Subject: [PATCH 17/40] Fix typos and improve some phrasings --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 4 ++-- CHANGELOG.md | 4 ++-- README.md | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 633e343..96fe0cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.9.9 # 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. + python-version: 3.9.9 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - name: Cache build id: restore-build uses: actions/cache@v2 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 10dac37..424e15a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,9 +10,9 @@ jobs: validate: uses: "./.github/workflows/validate.yml" - # GitHub Actions does not have a halt job option, to stop from deploying if no functional changes were found. + # 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. + # The `deploy` job is dependent on the output of the `check-for-functional-changes` job. check-for-functional-changes: runs-on: ubuntu-20.04 if: github.event.pull_request.merged == true diff --git a/CHANGELOG.md b/CHANGELOG.md index b3f48c7..d672d14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,9 @@ - Automate template setup process via CI for GitHub users: - When creating a new repository by using this template on GitHub, the setup script is automatically executed by the CI on the resulting generated repository. - Improve accessibility by adopting less technical terminology: - - Replaced "bootstrap" with "first-time setup," clarifying its purpose as a one-time project initialization, particularly useful for users unfamiliar with the technical vocabulary. + - Replace "bootstrap" with "first-time setup", clarifying its purpose as a one-time project initialisation, particularly for users unfamiliar with the technical vocabulary. - Decompose GitHub Actions monolithic workflow into specialized workflows: - - Split the `Country-Template` workflow into three distinct workflows: `build`, `validate` and `deploy` enhancing clarity and organization. + - Split the `Country-Template` workflow into three distinct workflows: `build`, `validate` and `deploy`. - Enhance accuracy of workflow triggers: - Trigger deployment exclusively when a PR is merged on the `main` branch - Trigger validation on PR events or as a dependency of the deployment workflow diff --git a/README.md b/README.md index ee718d2..dcc5803 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This set of instructions **only needs to be followed once** and will create your 2. Set the repository name to `openfisca-`; use underscore `_` or dash `-` as separators. For example, `openfisca-new_zealand`, `openfisca-new-zealand` or `openfisca-france`. -3. After being redirected to your newly created repository, please allow a short period for the automatic setup to be executed. Once done, the title of the readme should be updated to `OpenFisca `. +3. After being redirected to your newly created repository, please allow a few minutes for the automatic setup to be executed. Once done, the title of the readme should be updated to `OpenFisca `. > If the automatic setup does not start within a few minutes, you can initiate it manually: > - Navigate to the “Actions” tab. From c906b86ad7acc68243f955be063eec6fcc110866 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:20:48 +0200 Subject: [PATCH 18/40] Improve wording Co-authored-by: Matti Schneider --- CHANGELOG.md | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d672d14..bfecc32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,8 @@ - Decompose GitHub Actions monolithic workflow into specialized workflows: - Split the `Country-Template` workflow into three distinct workflows: `build`, `validate` and `deploy`. - Enhance accuracy of workflow triggers: - - Trigger deployment exclusively when a PR is merged on the `main` branch - - Trigger validation on PR events or as a dependency of the deployment workflow + - Trigger deployment exclusively when a PR is merged on the `main` branch. + - Trigger validation on PR events or as a dependency of the deployment workflow. ## 7.0.0 [#139](https://github.com/openfisca/country-template/pull/139) diff --git a/README.md b/README.md index dcc5803..c0a7644 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This set of instructions **only needs to be followed once** and will create your 1. Click on the [“Use this template” dropdown and select “Create a new repository”](https://github.com/new?template_name=country-template&template_owner=openfisca). -2. Set the repository name to `openfisca-`; use underscore `_` or dash `-` as separators. For example, `openfisca-new_zealand`, `openfisca-new-zealand` or `openfisca-france`. +2. Set the repository name to `openfisca-`; use underscore `_` as separator if there are spaces in the country name. For example, `openfisca-new_zealand` or `openfisca-france`. 3. After being redirected to your newly created repository, please allow a few minutes for the automatic setup to be executed. Once done, the title of the readme should be updated to `OpenFisca `. From 5c65f275088c9e51f7324f41dc388056ff5b2ade Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:22:03 +0200 Subject: [PATCH 19/40] Fix condition Co-authored-by: Matti Schneider --- first-time-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/first-time-setup.sh b/first-time-setup.sh index 8f58de7..5ee4e97 100755 --- a/first-time-setup.sh +++ b/first-time-setup.sh @@ -12,7 +12,7 @@ if [[ $JURISDICTION_NAME ]] && [[ $REPOSITORY_URL ]] then continue=Y fi -if [[ $CI ]] && [ ! -d .git ] +if [[ ! $CI ]] && [[ -d .git ]] then echo 'It seems you cloned this repository, or already initialised it.' echo 'Refusing to go further as you might lose work.' From dcec0738de6edbe264842fa7ecb35693fc876786 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:22:24 +0200 Subject: [PATCH 20/40] Unify syntax Co-authored-by: Matti Schneider --- first-time-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/first-time-setup.sh b/first-time-setup.sh index 5ee4e97..2fd9cd3 100755 --- a/first-time-setup.sh +++ b/first-time-setup.sh @@ -62,7 +62,7 @@ last_changelog_number=$(grep --line-number '^# Example Entry' CHANGELOG.md | cut first_commit_message='Initial import from OpenFisca country-template' second_commit_message='Customise country-template through script' -if [[ ! "$CI" ]] +if [[ ! $CI ]] then echo cd .. From fdeb4288bd183a094cd9680e86f6821dcc70bea9 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:23:09 +0200 Subject: [PATCH 21/40] Add comment Co-authored-by: Matti Schneider --- first-time-setup.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/first-time-setup.sh b/first-time-setup.sh index 2fd9cd3..2cde129 100755 --- a/first-time-setup.sh +++ b/first-time-setup.sh @@ -110,8 +110,7 @@ echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.y rm -f .github/workflows/first-time-setup.yml if [[ $CI ]] -then - exit 0 +then exit 0 # committing and tagging take directly place in the GitHub Actions workflow fi git add . From 6b5f74ddbef24af107f8d516ba57bdad881cfff3 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:33:27 +0200 Subject: [PATCH 22/40] Delete file via Git to ensure the removal will be committed --- first-time-setup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/first-time-setup.sh b/first-time-setup.sh index 2cde129..3eff99e 100755 --- a/first-time-setup.sh +++ b/first-time-setup.sh @@ -103,12 +103,12 @@ find . -name "*.template" -type f -delete echo -e "${PURPLE}* ${PURPLE}Rename package to: \033[0m${BLUE}$package_name\033[0m" git mv openfisca_country_template $package_name +echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.yml\033[0m${PURPLE} GitHub Action\033[0m" +git rm .github/workflows/first-time-setup.yml > /dev/null 2>&1 + echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.sh\033[0m${PURPLE} script\033[0m" git rm first-time-setup.sh > /dev/null 2>&1 -echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.yml\033[0m${PURPLE} GitHub Action\033[0m" -rm -f .github/workflows/first-time-setup.yml - if [[ $CI ]] then exit 0 # committing and tagging take directly place in the GitHub Actions workflow fi From 93bb53e3b02c29dd85fdaa4101125c187f107d86 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:50:26 +0200 Subject: [PATCH 23/40] Update stefanzweifel/git-auto-commit-action to v5 --- .github/workflows/first-time-setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/first-time-setup.yml b/.github/workflows/first-time-setup.yml index 9512ff4..b0fc8e5 100644 --- a/.github/workflows/first-time-setup.yml +++ b/.github/workflows/first-time-setup.yml @@ -28,7 +28,7 @@ jobs: run: CI=true JURISDICTION_NAME="$TITLE_CASE_JURISDICTION_NAME" REPOSITORY_URL="${{ github.repositoryUrl }}" ./first-time-setup.sh - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: "Customise country-template through CI" tagging_message: "0.0.1" From 1238ffbf8c7c416ad559d99e95ab1cb753bf5a8e Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 10:06:56 +0200 Subject: [PATCH 24/40] Remove obsolete IDs --- .github/workflows/build.yml | 2 -- .github/workflows/deploy.yml | 2 -- .github/workflows/validate.yml | 3 --- 3 files changed, 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 96fe0cc..c3b76b4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,6 @@ jobs: with: python-version: 3.9.9 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - name: Cache build - id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} @@ -26,7 +25,6 @@ jobs: - name: Build package run: make build - name: Cache release - id: restore-release uses: actions/cache@v2 with: path: dist diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f1050ac..e65c880 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -44,13 +44,11 @@ jobs: with: python-version: 3.9.9 - name: Cache build - id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - name: Cache release - id: restore-release uses: actions/cache@v2 with: path: dist diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 715b09e..bfa539f 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -22,7 +22,6 @@ jobs: with: python-version: 3.9.9 - name: Cache build - id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} @@ -44,7 +43,6 @@ jobs: with: python-version: 3.9.9 - name: Cache build - id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} @@ -61,7 +59,6 @@ jobs: with: python-version: 3.9.9 - name: Cache build - id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} From faea0bcc4ac1749c7161b2a7c7818065261eae4d Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 10:11:47 +0200 Subject: [PATCH 25/40] Improve naming --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 2 +- .github/workflows/validate.yml | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c3b76b4..da2147b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9.9 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - - name: Cache build + - name: Restore build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e65c880..a94709d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -43,7 +43,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9.9 - - name: Cache build + - name: Restore build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index bfa539f..5d28c32 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -21,7 +21,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9.9 - - name: Cache build + - name: Restore build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} @@ -42,7 +42,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9.9 - - name: Cache build + - name: Restore build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} @@ -58,7 +58,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9.9 - - name: Cache build + - name: Restore build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} From 01be1753218204364d00078792112b529ddc321b Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 10:30:01 +0200 Subject: [PATCH 26/40] Remove obsolete checkout option --- .github/workflows/deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a94709d..4094704 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -37,8 +37,6 @@ jobs: PYPI_TOKEN_OPENFISCA_BOT: ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} steps: - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all the tags - name: Set up Python uses: actions/setup-python@v2 with: From 0dcdbcf57e6d262bd58e5037c8e8da1accfca1a1 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 10:31:17 +0200 Subject: [PATCH 27/40] Remove manual trigger on `build` and `validate` workflows --- .github/workflows/build.yml | 1 - .github/workflows/validate.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index da2147b..c272840 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,6 @@ name: Build on: workflow_call: - workflow_dispatch: jobs: build: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 5d28c32..96de6a7 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -3,7 +3,6 @@ name: Validate on: pull_request: types: [ assigned, opened, reopened, synchronize, ready_for_review ] - workflow_dispatch: workflow_call: jobs: From 4130dfe54dae39efbc3c253801f4443b7a5b92e4 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:51:44 +0200 Subject: [PATCH 28/40] Update Ubuntu to `v22.04` on CI --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 4 ++-- .github/workflows/validate.yml | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c272840..59a14ae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v2 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4094704..5879840 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,7 +14,7 @@ jobs: # 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-20.04 + runs-on: ubuntu-22.04 if: github.event.pull_request.merged == true outputs: status: ${{ steps.stop-early.outputs.status }} @@ -30,7 +30,7 @@ jobs: run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi deploy: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: [ validate, check-for-functional-changes ] if: github.event.pull_request.merged == true && needs.check-for-functional-changes.outputs.status == 'success' env: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 96de6a7..a90cb02 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -10,7 +10,7 @@ jobs: uses: "./.github/workflows/build.yml" lint-files: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: [ build ] steps: - uses: actions/checkout@v2 @@ -33,7 +33,7 @@ jobs: run: "${GITHUB_WORKSPACE}/.github/lint-changed-yaml-tests.sh" test-yaml: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: [ build ] steps: - uses: actions/checkout@v2 @@ -49,7 +49,7 @@ jobs: - run: make test test-api: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: [ build ] steps: - uses: actions/checkout@v2 @@ -66,7 +66,7 @@ jobs: run: "${GITHUB_WORKSPACE}/.github/test-api.sh" check-version-and-changelog: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: From 7d13315e471200049c748e167ab85b15bd3f42cb Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:54:08 +0200 Subject: [PATCH 29/40] Update CI dependency `actions/setup-python` to `v5` --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 4 ++-- .github/workflows/validate.yml | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59a14ae..ca74fd5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9.9 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - name: Restore build diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5879840..dae59af 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,7 +23,7 @@ jobs: with: fetch-depth: 0 # Fetch all the tags - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9.9 - id: stop-early @@ -38,7 +38,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9.9 - name: Restore build diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index a90cb02..ecbe900 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -17,7 +17,7 @@ jobs: with: fetch-depth: 0 # Fetch all the tags - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9.9 - name: Restore build @@ -38,7 +38,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9.9 - name: Restore build @@ -54,7 +54,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9.9 - name: Restore build @@ -72,7 +72,7 @@ jobs: with: fetch-depth: 0 # Fetch all the tags - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9.9 - name: Check version number has been properly updated From b3e4ebbaaeff0260a28d0c8b1c127dc91afff1b5 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:58:39 +0200 Subject: [PATCH 30/40] Update Python to `v3.9.12` on CI Python `v3.9.9` is not available for Ubuntu `v22.04` --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 4 ++-- .github/workflows/validate.yml | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca74fd5..1563a24 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. + python-version: 3.9.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - name: Restore build uses: actions/cache@v2 with: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dae59af..11b4e32 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,7 +25,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 + python-version: 3.9.12 - id: stop-early run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi @@ -40,7 +40,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 + python-version: 3.9.12 - name: Restore build uses: actions/cache@v2 with: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index ecbe900..96d2202 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 + python-version: 3.9.12 - name: Restore build uses: actions/cache@v2 with: @@ -40,7 +40,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 + python-version: 3.9.12 - name: Restore build uses: actions/cache@v2 with: @@ -56,7 +56,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 + python-version: 3.9.12 - name: Restore build uses: actions/cache@v2 with: @@ -74,6 +74,6 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 + python-version: 3.9.12 - name: Check version number has been properly updated run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" From 71b05d3fb5fd6d1b309a964dae33ed7f4a2bb461 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 10:04:01 +0200 Subject: [PATCH 31/40] Update CI dependency `actions/checkout` to `v4` --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 4 ++-- .github/workflows/validate.yml | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1563a24..f65c0e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 11b4e32..ad27c34 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,7 +19,7 @@ jobs: outputs: status: ${{ steps.stop-early.outputs.status }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all the tags - name: Set up Python @@ -36,7 +36,7 @@ jobs: env: PYPI_TOKEN_OPENFISCA_BOT: ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 96d2202..2e9f1e0 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-22.04 needs: [ build ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all the tags - name: Set up Python @@ -36,7 +36,7 @@ jobs: runs-on: ubuntu-22.04 needs: [ build ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: @@ -52,7 +52,7 @@ jobs: runs-on: ubuntu-22.04 needs: [ build ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: @@ -68,7 +68,7 @@ jobs: check-version-and-changelog: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all the tags - name: Set up Python From 830be467149dcafe22689988da06e582a9790c2b Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 10:05:37 +0200 Subject: [PATCH 32/40] Update CI dependency `actions/cache` to `v4` --- .github/workflows/build.yml | 4 ++-- .github/workflows/deploy.yml | 4 ++-- .github/workflows/validate.yml | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f65c0e8..093234e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: with: python-version: 3.9.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - name: Restore build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} # Cache the entire build Python environment @@ -24,7 +24,7 @@ jobs: - name: Build package run: make build - name: Cache release - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: dist key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ad27c34..94c060f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -42,12 +42,12 @@ jobs: with: python-version: 3.9.12 - name: Restore build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - name: Cache release - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: dist key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 2e9f1e0..5241f27 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -21,7 +21,7 @@ jobs: with: python-version: 3.9.12 - name: Restore build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} @@ -42,7 +42,7 @@ jobs: with: python-version: 3.9.12 - name: Restore build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} @@ -58,7 +58,7 @@ jobs: with: python-version: 3.9.12 - name: Restore build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} From 6df2cb82503ae670a001bb1a017c3a0302d03461 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 15:33:44 +0200 Subject: [PATCH 33/40] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43c9c75..00c845a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Enhance accuracy of workflow triggers: - Trigger deployment exclusively when a PR is merged on the `main` branch. - Trigger validation on PR events or as a dependency of the deployment workflow. + - Update CI dependencies # 7.0.0 [#139](https://github.com/openfisca/country-template/pull/139) From 3e012098da6460076dd803d8ad8e30c15a2b837f Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Fri, 3 May 2024 16:37:02 +0200 Subject: [PATCH 34/40] Improve copywriting --- .github/workflows/deploy.yml | 5 ++--- .github/workflows/first-time-setup.yml | 2 +- README.md | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 94c060f..716806f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -11,8 +11,7 @@ jobs: uses: "./.github/workflows/validate.yml" # 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. + # We thus execute a separate deployment job depending on the output of this job. check-for-functional-changes: runs-on: ubuntu-22.04 if: github.event.pull_request.merged == true @@ -46,7 +45,7 @@ jobs: with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - name: Cache release + - name: Restore built package uses: actions/cache@v4 with: path: dist diff --git a/.github/workflows/first-time-setup.yml b/.github/workflows/first-time-setup.yml index b0fc8e5..31b5537 100644 --- a/.github/workflows/first-time-setup.yml +++ b/.github/workflows/first-time-setup.yml @@ -20,7 +20,7 @@ jobs: with: repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Set environment variables + - name: Infer jurisdiction name from repository name run: | echo "TITLE_CASE_JURISDICTION_NAME=$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//' | sed 's/[-|_]/ /g' | awk '{for (i=1; i<=NF; i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1')" >> $GITHUB_ENV diff --git a/README.md b/README.md index c0a7644..1fbbe62 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This set of instructions **only needs to be followed once** and will create your 2. Set the repository name to `openfisca-`; use underscore `_` as separator if there are spaces in the country name. For example, `openfisca-new_zealand` or `openfisca-france`. -3. After being redirected to your newly created repository, please allow a few minutes for the automatic setup to be executed. Once done, the title of the readme should be updated to `OpenFisca `. +3. After being redirected to your newly created repository, please allow a few minutes for the automatic setup to be executed. Once done, the title of the README file should be updated to `OpenFisca `. > If the automatic setup does not start within a few minutes, you can initiate it manually: > - Navigate to the “Actions” tab. From 5b43f1a64569c158508884bf121ea011d3fd11d2 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 16:44:04 +0200 Subject: [PATCH 35/40] Fix step name Co-authored-by: Matti Schneider --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 093234e..a42811d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: uses: actions/setup-python@v5 with: python-version: 3.9.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - - name: Restore build + - name: Cache build uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} From 50b840851ece68bd5cbff60be53b60d3b8ed6388 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 16:57:30 +0200 Subject: [PATCH 36/40] Trigger deployment on any push to `main` --- .github/workflows/deploy.yml | 9 +++------ CHANGELOG.md | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 716806f..ae68a6d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,10 +1,8 @@ name: Deploy on: - pull_request_target: - branches: - - main - types: [ closed ] + push: + branches: [ main ] jobs: validate: @@ -14,7 +12,6 @@ jobs: # We thus execute a separate deployment job depending on the output of this job. check-for-functional-changes: runs-on: ubuntu-22.04 - if: github.event.pull_request.merged == true outputs: status: ${{ steps.stop-early.outputs.status }} steps: @@ -31,9 +28,9 @@ jobs: deploy: runs-on: ubuntu-22.04 needs: [ validate, check-for-functional-changes ] - if: github.event.pull_request.merged == true && needs.check-for-functional-changes.outputs.status == 'success' env: PYPI_TOKEN_OPENFISCA_BOT: ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} + if: needs.check-for-functional-changes.outputs.status == 'success' steps: - uses: actions/checkout@v4 - name: Set up Python diff --git a/CHANGELOG.md b/CHANGELOG.md index 00c845a..ecd91df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ - Decompose GitHub Actions monolithic workflow into specialized workflows: - Split the `Country-Template` workflow into three distinct workflows: `build`, `validate` and `deploy`. - Enhance accuracy of workflow triggers: - - Trigger deployment exclusively when a PR is merged on the `main` branch. + - Trigger deployment only when changes are pushed to the `main` branch. - Trigger validation on PR events or as a dependency of the deployment workflow. - Update CI dependencies From dd4f13b8405faf0290a1039b028a78d843a7fab9 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 16:57:45 +0200 Subject: [PATCH 37/40] Simplify code --- .github/workflows/deploy.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ae68a6d..34dd027 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,8 +28,6 @@ jobs: deploy: runs-on: ubuntu-22.04 needs: [ validate, check-for-functional-changes ] - env: - PYPI_TOKEN_OPENFISCA_BOT: ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} if: needs.check-for-functional-changes.outputs.status == 'success' steps: - uses: actions/checkout@v4 @@ -48,6 +46,6 @@ jobs: 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 $PYPI_TOKEN_OPENFISCA_BOT + run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} - name: Publish a git tag run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" From 3f351331b178e3f02708962bd224cd6f8332c233 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 16:58:30 +0200 Subject: [PATCH 38/40] Use consistent line breaks across workflows --- .github/workflows/build.yml | 4 ++++ .github/workflows/validate.yml | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a42811d..419e8b0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,10 +9,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: Set up Python uses: actions/setup-python@v5 with: python-version: 3.9.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. + - name: Cache build uses: actions/cache@v4 with: @@ -21,8 +23,10 @@ jobs: restore-keys: | build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }} build-${{ env.pythonLocation }}- + - name: Build package run: make build + - name: Cache release uses: actions/cache@v4 with: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 5241f27..982ee85 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -16,19 +16,25 @@ jobs: - 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.12 + - name: Restore build 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 Python files run: "${GITHUB_WORKSPACE}/.github/lint-changed-python-files.sh" + - name: Lint YAML tests run: "${GITHUB_WORKSPACE}/.github/lint-changed-yaml-tests.sh" @@ -37,15 +43,18 @@ jobs: needs: [ build ] steps: - uses: actions/checkout@v4 + - name: Set up Python uses: actions/setup-python@v5 with: python-version: 3.9.12 + - name: Restore build uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} + - run: make test test-api: @@ -53,15 +62,18 @@ jobs: needs: [ build ] steps: - uses: actions/checkout@v4 + - name: Set up Python uses: actions/setup-python@v5 with: python-version: 3.9.12 + - name: Restore build 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" @@ -71,9 +83,11 @@ jobs: - 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.12 + - name: Check version number has been properly updated run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" From 73ba03b156bad53d33e86f4c1a60918fd36f1bf9 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 17:01:56 +0200 Subject: [PATCH 39/40] Reduce logs --- first-time-setup.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/first-time-setup.sh b/first-time-setup.sh index 3eff99e..a64b3b3 100755 --- a/first-time-setup.sh +++ b/first-time-setup.sh @@ -103,10 +103,8 @@ find . -name "*.template" -type f -delete echo -e "${PURPLE}* ${PURPLE}Rename package to: \033[0m${BLUE}$package_name\033[0m" git mv openfisca_country_template $package_name -echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.yml\033[0m${PURPLE} GitHub Action\033[0m" +echo -e "${PURPLE}* ${PURPLE}Remove single use first time setup files\033[0m" git rm .github/workflows/first-time-setup.yml > /dev/null 2>&1 - -echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.sh\033[0m${PURPLE} script\033[0m" git rm first-time-setup.sh > /dev/null 2>&1 if [[ $CI ]] From e70eaf8833baf874bfc2b7750694172cd3f2e9f0 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 17:08:05 +0200 Subject: [PATCH 40/40] Improve job name --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 419e8b0..b38ed1a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: workflow_call: jobs: - build: + build-and-cache: runs-on: ubuntu-22.04 steps: - name: Checkout