workflow: add tag parsing #502
Workflow file for this run
This file contains 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: CI | |
on: | |
push: | |
tags: | |
- "v*.*.*" | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
jobs: | |
build: | |
name: Run tests & display coverage | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo "event name is:" ${{ github.event_name }} | |
- run: echo "event type is:" ${{ github.event.action }} | |
- run: echo "event ref is:" ${{ github.ref }} | |
- uses: actions/checkout@v2 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: "3.10" | |
- name: Install developer dependencies | |
run: make install-dependencies | |
- name: Lint with flake8 | |
run: make flake8 | |
- name: Run tests and produce .coverage file | |
run: make test | |
- name: Coverage comment | |
id: coverage_comment | |
uses: py-cov-action/python-coverage-comment-action@v3 | |
with: | |
GITHUB_TOKEN: ${{ github.token }} | |
- name: Check coding style | |
run: make black-check | |
- name: Store Pull Request comment to be posted | |
uses: actions/upload-artifact@v3 | |
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true' | |
with: | |
# If you use a different name, update COMMENT_ARTIFACT_NAME accordingly | |
name: python-coverage-comment-action | |
# If you use a different name, update COMMENT_FILENAME accordingly | |
path: python-coverage-comment-action.txt | |
flake8-badge: | |
if: github.event_name == 'push' | |
name: Update flake8 badge | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: "3.10" | |
- name: Install developer dependencies | |
run: make install-dependencies | |
- name: Lint with flake8 | |
run: make flake8 | |
- name: Determine badge message and color | |
run: make flake8-badge | tail -1 | (IFS="@" read MESSAGE COLOR; | |
echo "FLAKE8_BADGE_MESSAGE=$MESSAGE" >> $GITHUB_ENV; | |
echo "FLAKE8_BADGE_COLOR=$COLOR" >> $GITHUB_ENV) | |
- name: Set up JSON file for badge | |
uses: schneegans/dynamic-badges-action@v1.6.0 | |
with: | |
auth: ${{ secrets.GIST_SECRET }} | |
gistID: 1cfaee423c85504cd204cf4649e2cf29 | |
filename: flake8-badge.json | |
label: flake8 | |
message: ${{ env.FLAKE8_BADGE_MESSAGE }} | |
color: ${{ env.FLAKE8_BADGE_COLOR }} | |
eslint-badge: | |
if: github.event_name == 'push' | |
name: Update eslint badge | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18.x" | |
- name: Setup JS environment | |
run: cd js && npm install | |
- name: Determine badge message and color | |
run: make eslint-badge | tail -1 | (IFS="@" read MESSAGE COLOR; | |
echo "ESLINT_BADGE_MESSAGE=$MESSAGE" >> $GITHUB_ENV; | |
echo "ESLINT_BADGE_COLOR=$COLOR" >> $GITHUB_ENV) | |
- name: Set up JSON file for badge | |
uses: schneegans/dynamic-badges-action@v1.6.0 | |
with: | |
auth: ${{ secrets.GIST_SECRET }} | |
gistID: 1cfaee423c85504cd204cf4649e2cf29 | |
filename: eslint-badge.json | |
label: eslint | |
message: ${{ env.ESLINT_BADGE_MESSAGE }} | |
color: ${{ env.ESLINT_BADGE_COLOR }} | |
# based on https://stackoverflow.com/a/64373702 | |
build-docker: | |
name: Build docker image & run tests | |
runs-on: ubuntu-latest | |
env: | |
COMPOSE_FILE: docker/docker-compose.yml | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Build docker images | |
run: docker-compose build web | |
- name: Run tests | |
run: docker-compose run web python -m pytest | |
push-docker: | |
if: github.event_name == 'push' | |
name: Push docker image | |
runs-on: ubuntu-latest | |
env: | |
COMPOSE_FILE: docker/docker-compose.yml | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Build docker images | |
run: docker-compose build web | |
- name: Login to ghcr | |
run: echo ${{ github.token }} | docker login ghcr.io -u hgrf --password-stdin | |
- name: Push to ghcr | |
run: docker push ghcr.io/hgrf/racine:latest | |
- name: Push to ghcr (tagged) | |
if: startsWith(github.ref, 'refs/tags/') | |
run: | | |
sed s'/refs\/tags\///g' <(echo "${{ github.ref }}") | (read TAG; \ | |
docker tag ghcr.io/hgrf/racine:latest \ | |
ghcr.io/hgrf/racine:$TAG && \ | |
docker push ghcr.io/hgrf/racine:$TAG && \ | |
echo Successfully pushed ghcr.io/hgrf/racine:$TAG | |
) | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
if: startsWith(github.ref, 'refs/tags/') |