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

Skip deploy workflow when PyPI token is not defined in GitHub secrets #147

Merged
merged 15 commits into from
May 10, 2024
Merged
7 changes: 6 additions & 1 deletion .github/lint-changed-python-files.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#! /usr/bin/env bash

last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit
last_tagged_commit=`git describe --always --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit

if [ $? -ne 0 ]; then
echo "Error: Failed to find the last tagged commit."
exit 1
fi

if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "*.py")
then
Expand Down
7 changes: 6 additions & 1 deletion .github/lint-changed-yaml-tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#! /usr/bin/env bash

last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit
last_tagged_commit=`git describe --always --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit

if [ $? -ne 0 ]; then
echo "Error: Failed to find the last tagged commit."
exit 1
fi

if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "tests/*.yaml")
then
Expand Down
25 changes: 21 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,29 @@ jobs:
with:
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
run: |
if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then
echo "status=success" >> $GITHUB_OUTPUT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go multiline, let's do it all the way 😉

Suggested change
if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then
echo "status=success" >> $GITHUB_OUTPUT
if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh"
then echo "status=success" >> $GITHUB_OUTPUT

fi

check-pypi-token:
runs-on: ubuntu-22.04
outputs:
pypi_token_present: ${{ steps.check_token.outputs.pypi_token_present }}
steps:
- name: Check PYPI Token
Ndpnt marked this conversation as resolved.
Show resolved Hide resolved
id: check_token
run: |
if [[ -n "${{ secrets.PYPI_TOKEN }}" ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment you made in the commit to explain the implementation is really good, but it would be useful to also have it as a comment in the code to save some future smartass 😉

echo "pypi_token_present=true" >> $GITHUB_OUTPUT
else
echo "pypi_token_present=false" >> $GITHUB_OUTPUT
fi

deploy:
runs-on: ubuntu-22.04
needs: [ validate, check-for-functional-changes ]
if: needs.check-for-functional-changes.outputs.status == 'success'
needs: [ validate, check-for-functional-changes, check-pypi-token ]
if: needs.check-for-functional-changes.outputs.status == 'success' && needs.check-pypi-token.outputs.pypi_token_present == 'true'
steps:
- uses: actions/checkout@v4
- name: Set up Python
Expand All @@ -46,6 +63,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 ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }}
run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_TOKEN }}
- name: Publish a git tag
run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh"
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

### 7.1.2 [#147](https://github.com/openfisca/country-template/pull/147)

* Technical improvement
* Details:
- Skip `deploy` workflow when PyPI token is not defined in GitHub secrets
- Ensure lint scripts work properly without reachable tags
- Rename the GitHub secret `PYPI_TOKEN_OPENFISCA_BOT` used in `deploy` workflow to `PYPI_TOKEN`
- Update deprecated syntax in GitHub Action workflow
Ndpnt marked this conversation as resolved.
Show resolved Hide resolved

### 7.1.1 [#146](https://github.com/openfisca/country-template/pull/146)

* Technical improvement
Expand Down
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,35 @@ The files that are outside from the `openfisca_country_template` folder are used

## Packaging your Country Package for Distribution

Country packages are python distributions. To distribute your package via `pip`, follow the steps given by the [Python Packaging Authority](https://python-packaging-user-guide.readthedocs.io/tutorials/distributing-packages/#packaging-your-project).
Country packages are Python distributions. You can choose to distribute your package automatically via our continuous deployment system on GitHub, or manually.
Ndpnt marked this conversation as resolved.
Show resolved Hide resolved

### Automatic continuous deployment on GitHub

This repository is configured with a continuous deployment system to automate the distribution of your package via `pip`.

#### Setting up continuous deployment

To activate the continuous deployment:

1. Create an account on [PyPI](https://pypi.org/) if you don't already have one.
2. Generate a token in your PyPI account. This token will allow GitHub Actions to securely upload new versions of your package to PyPI.
3. Add this token to your GitHub repository's secrets under the name `PYPI_TOKEN`.

Once set up, changes to the `main` branch will trigger an automated workflow to build and publish your package to PyPI, making it available for `pip` installation.

### Manual distribution

If you prefer to manually manage the release and distribution of your package, follow the guidelines provided by the [Python Packaging Authority](https://python-packaging-user-guide.readthedocs.io/tutorials/distributing-packages/#packaging-your-project).

This involves detailed steps on preparing your package, creating distribution files, and uploading them to PyPI.

### Accessing your package

Once deployed, your package can be easily installed by users with the following command:

```sh
pip install openfisca-<your_country_name>
```
Ndpnt marked this conversation as resolved.
Show resolved Hide resolved

## Install Instructions for Users and Contributors

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "openfisca-country_template"
version = "7.1.1"
version = "7.1.2"
description = "OpenFisca Rules as Code model for Country-Template."
readme = "README.md"
keywords = ["microsimulation", "tax", "benefit", "rac", "rules-as-code"]
Expand Down