Skip to content

Publish Scraper pypi package and create a release #2

Publish Scraper pypi package and create a release

Publish Scraper pypi package and create a release #2

name: Publish Scraper pypi package and create a release
on:
workflow_dispatch:
inputs:
bump:
description: "Bump the version of the scraper"
type: choice
required: true
default: "patch"
options:
- "patch"
- "minor"
- "major"
- "prepatch"
- "preminor"
- "premajor"
env:
DRAFT: ${{ contains(inputs.bump, 'pre') }}
jobs:
python_project:
name: Build ecoindex Scraper python project
runs-on: ubuntu-latest
outputs:
wheel: ${{ steps.wheel.outputs.wheel }}
scraper_version: ${{ steps.version.outputs.scraper_version }}
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Task
uses: arduino/setup-task@v2
with:
version: 3.x
- name: Install poetry
uses: abatilo/actions-poetry@v2
- name: Install poetry build project
run: pip install poetry-multiproject-plugin
- name: Bump version
run: task scraper:bump -- ${{ github.event.inputs.bump }}
- name: Build
run: task scraper:poetry:build
- name: Upload version to artifacts
uses: actions/upload-artifact@v4
with:
name: version
path: components/ecoindex/scraper/VERSION
- name: Upload pyproject.toml to artifacts
uses: actions/upload-artifact@v4
with:
name: pyproject
path: projects/ecoindex_scraper/pyproject.toml
- name: Upload dist folder
uses: actions/upload-artifact@v4
with:
name: dist
path: projects/ecoindex_scraper/dist
- name: Output version
id: version
run: echo "scraper_version=$(task scraper:poetry:version-short)" >> $GITHUB_OUTPUT
- name: Output wheel
id: wheel
run: echo "wheel=ecoindex_scraper-${{ steps.version.outputs.scraper_version }}-py3-none-any.whl" >> $GITHUB_OUTPUT
- name: Output summary
run: |
echo "Scraper version ${{ steps.version.outputs.scraper_version }}" >> $GITHUB_STEP_SUMMARY
echo "Wheel ${{ steps.wheel.outputs.wheel }}" >> $GITHUB_STEP_SUMMARY
pypi_package:
name: Build and push scraper pypi package
runs-on: ubuntu-latest
needs: python_project
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Install Task
uses: arduino/setup-task@v2
with:
version: 3.x
- name: Download dist from artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: projects/ecoindex_scraper/dist
- name: Download pyproject.toml from artifacts
uses: actions/download-artifact@v4
with:
name: pyproject
path: /tmp
- name: Copy pyproject.toml to the project
run: cp /tmp/pyproject.toml projects/ecoindex_scraper/pyproject.toml
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install poetry
uses: abatilo/actions-poetry@v2
- name: Login to Pypi
run: poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
- name: Publish
run: task scraper:pypi:publish
release:
name: Create a release
runs-on: ubuntu-latest
needs: [python_project, pypi_package]
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Git pull
run: git pull
- name: Download pyproject.toml to a temporary file
uses: actions/download-artifact@v4
with:
name: pyproject
path: /tmp
- name: Download VERSION to a temporary file
uses: actions/download-artifact@v4
with:
name: version
path: /tmp
- name: Copy and overwrite existing files to the repo
run: |
cp /tmp/pyproject.toml projects/ecoindex_scraper/pyproject.toml
cp /tmp/VERSION components/ecoindex/scraper/VERSION
- name: Get last tag (that is not a `pre` tag) for scraper
id: last_tag
run: echo "last_tag=$(git tag --list | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+@scraper$' | sort -r | head -n 1)" >> $GITHUB_OUTPUT
- name: Commit files
uses: EndBug/add-and-commit@v9
with:
message: "chore(scraper): Bump scraper version to ${{ needs.python_project.outputs.scraper_version }}"
tag: v${{ needs.python_project.outputs.scraper_version }}@scraper
tag_push: "--force"
push: true
- name: Update CHANGELOG
id: changelog
uses: requarks/changelog-action@v1
with:
token: ${{ github.token }}
fromTag: v${{ needs.python_project.outputs.scraper_version }}@scraper
toTag: ${{ steps.last_tag.outputs.last_tag }}
excludeScopes: api,cli
changelogFilePath: /tmp/changelog.md
- name: Update changelog content with dockerhub links
run: |
echo "" >> /tmp/changelog.md
echo "### Pypi package" >> /tmp/changelog.md
echo "" >> /tmp/changelog.md
echo "Pypi package have been built and pushed to Pypi: [ecoindex-scraper:${{ needs.python_project.outputs.scraper_version }}](https://pypi.org/project/ecoindex-scraper/${{ needs.python_project.outputs.scraper_version }}/)" >> /tmp/changelog.md
- name: Create Release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
draft: ${{ env.DRAFT }}
makeLatest: true
name: "Scraper: v${{ needs.python_project.outputs.scraper_version }}"
tag: v${{ needs.python_project.outputs.scraper_version }}@scraper
token: ${{ github.token }}
bodyFile: /tmp/changelog.md