Publish CLI Docker image, pypi package and create a release #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish CLI Docker image, pypi package and create a release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: "Bump the version of the CLI" | |
| type: choice | |
| required: true | |
| default: "patch" | |
| options: | |
| - "patch" | |
| - "minor" | |
| - "major" | |
| - "prepatch" | |
| - "preminor" | |
| - "premajor" | |
| env: | |
| PRERELEASE: ${{ contains(inputs.bump, 'pre') }} | |
| jobs: | |
| python_project: | |
| name: Build ecoindex CLI python project | |
| runs-on: ubuntu-latest | |
| outputs: | |
| wheel: ${{ steps.wheel.outputs.wheel }} | |
| version: ${{ steps.version.outputs.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 cli:bump -- ${{ github.event.inputs.bump }} | |
| - name: Build | |
| run: task cli:poetry:build | |
| - name: Upload version to artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: version | |
| path: bases/ecoindex/cli/VERSION | |
| - name: Upload pyproject.toml to artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pyproject | |
| path: projects/ecoindex_cli/pyproject.toml | |
| - name: Upload dist folder | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist | |
| path: projects/ecoindex_cli/dist | |
| - name: Output version | |
| id: version | |
| run: echo "version=$(task cli:poetry:version-short)" >> $GITHUB_OUTPUT | |
| - name: Output wheel | |
| id: wheel | |
| run: echo "wheel=ecoindex_cli-${{ steps.version.outputs.version }}-py3-none-any.whl" >> $GITHUB_OUTPUT | |
| - name: Output summary | |
| run: | | |
| echo "CLI version ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "Wheel ${{ steps.wheel.outputs.wheel }}" >> $GITHUB_STEP_SUMMARY | |
| docker_image: | |
| name: Build and push CLI image to docker hub | |
| runs-on: ubuntu-latest | |
| needs: python_project | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@v4 | |
| - name: Download dist from artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| path: projects/ecoindex_cli/dist | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v4 | |
| with: | |
| images: vvatelot/ecoindex-cli | |
| - name: Build and push | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: projects/ecoindex_cli | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }},vvatelot/ecoindex-cli:${{ needs.python_project.outputs.version }},${{ !contains(inputs.bump, 'pre') && 'vvatelot/ecoindex-cli:latest' || '' }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| file: projects/ecoindex_cli/dockerfile | |
| build-args: wheel=${{ needs.python_project.outputs.wheel }} | |
| pypi_package: | |
| name: Build and push CLI 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_cli/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_cli/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 cli:pypi:publish | |
| release: | |
| name: Create a release | |
| runs-on: ubuntu-latest | |
| needs: [python_project, docker_image, 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_cli/pyproject.toml | |
| cp /tmp/VERSION bases/ecoindex/cli/VERSION | |
| - uses: oprypin/find-latest-tag@v1 | |
| id: last_tag | |
| with: | |
| repository: ${{ github.repository }} | |
| releases-only: false | |
| regex: '^v[0-9]+\.[0-9]+\.[0-9]+@cli$' | |
| - name: Commit files | |
| uses: EndBug/add-and-commit@v9 | |
| with: | |
| message: "chore(cli): Bump CLI version to ${{ needs.python_project.outputs.version }}" | |
| tag: v${{ needs.python_project.outputs.version }}@cli | |
| 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.version }}@cli | |
| toTag: ${{ steps.last_tag.outputs.tag }} | |
| excludeScopes: api | |
| changelogFilePath: /tmp/changelog.md | |
| - name: Update changelog content with dockerhub links | |
| run: | | |
| echo "${{ steps.changelog.outputs.changes }}" > /tmp/changelog.md | |
| echo "" >> /tmp/changelog.md | |
| echo "### Docker image" >> /tmp/changelog.md | |
| echo "" >> /tmp/changelog.md | |
| echo "Docker image have been built and pushed to Docker Hub: [vvatelot/cli:${{ needs.python_project.outputs.version }}](https://hub.docker.com/r/vvatelot/ecoindex-cli/tags?page=1&name=${{ needs.python_project.outputs.version }})" >> /tmp/changelog.md | |
| 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-cli:${{ needs.python_project.outputs.version }}](https://pypi.org/project/ecoindex-cli/${{ needs.python_project.outputs.version }}/)" >> /tmp/changelog.md | |
| - name: Create Release | |
| id: create_release | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| allowUpdates: true | |
| prerelease: ${{ env.PRERELEASE }} | |
| makeLatest: true | |
| name: "CLI: v${{ needs.python_project.outputs.version }}" | |
| tag: v${{ needs.python_project.outputs.version }}@cli | |
| token: ${{ github.token }} | |
| bodyFile: /tmp/changelog.md | |
| - name: Notify to Mattermost | |
| if: ${{ env.PRERELEASE != 'true' }} | |
| run: | | |
| echo -e "{\"icon_url\":\"https://icon-library.com/images/github-icon-png/github-icon-png-29.jpg\",\"text\":\":tada: Une nouvelle release a été publiée pour le projet **${{ github.repository }}: v${{ needs.python_project.outputs.version }}** :tada: \n\nPlus d'infos ici: ${{ steps.create_release.outputs.html_url }}\"}" > mattermost.json | |
| curl -X POST -H 'Content-Type: application/json' -d @mattermost.json ${{ secrets.MATTERMOST_RELEASE_URL }} |