Skip to content

Commit

Permalink
ci: update all workflows to gh-workflows reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Oct 9, 2023
1 parent 4b97275 commit df2cc31
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 138 deletions.
52 changes: 14 additions & 38 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,19 @@ on:
# Allow manual trigger
workflow_dispatch:

env:
REGISTRY: ghcr.io
GIT_BRANCH: ${{ github.ref_name }}

jobs:
build-and-push-images:
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract version
id: extract_api_version
run: |
echo "PKG_VERSION=$(python -c 'from fmtm_splitter.__version__ import __version__; print(__version__)')" >> $GITHUB_ENV
extract-vars:
uses: hotosm/gh-workflows/.github/workflows/py_app_version.yml@main
with:
package_name: fmtm_splitter

- name: Build image
uses: docker/build-push-action@v4
with:
context: .
target: ci
push: true
tags: |
"ghcr.io/hotosm/fmtm-splitter:${{ env.PKG_VERSION }}-ci"
"ghcr.io/hotosm/fmtm-splitter:ci"
build-args: |
PKG_VERSION=${{ env.PKG_VERSION }}
backend-ci-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@main
needs: [extract-vars]
with:
build_target: ci
image_tags: |
"ghcr.io/hotosm/fmtm-splitter:${{ needs.extract-vars.outputs.app_version }}-ci"
"ghcr.io/hotosm/fmtm-splitter:ci"
build_args: |
PKG_VERSION=${{ needs.extract-vars.outputs.app_version }}
52 changes: 14 additions & 38 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,19 @@ on:
# Allow manual trigger
workflow_dispatch:

env:
REGISTRY: ghcr.io
GIT_BRANCH: ${{ github.ref_name }}

jobs:
build-and-push-images:
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract version
id: extract_api_version
run: |
echo "PKG_VERSION=$(python -c 'from fmtm_splitter.__version__ import __version__; print(__version__)')" >> $GITHUB_ENV
extract-vars:
uses: hotosm/gh-workflows/.github/workflows/py_app_version.yml@main
with:
package_name: fmtm_splitter

- name: Build image
uses: docker/build-push-action@v4
with:
context: .
target: prod
push: true
tags: |
"ghcr.io/hotosm/fmtm-splitter:${{ env.PKG_VERSION }}"
"ghcr.io/hotosm/fmtm-splitter:latest"
build-args: |
PKG_VERSION=${{ env.PKG_VERSION }}
backend-ci-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@main
needs: [extract-vars]
with:
build_target: prod
image_tags: |
"ghcr.io/hotosm/fmtm-splitter:${{ needs.extract-vars.outputs.app_version }}"
"ghcr.io/hotosm/fmtm-splitter:latest"
build_args: |
PKG_VERSION=${{ needs.extract-vars.outputs.app_version }}
52 changes: 24 additions & 28 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,36 @@ on:
paths:
- docs/**
- fmtm_splitter/**
- mkdocs.yml
branches: [main]
# Allow manual trigger (workflow_dispatch)
workflow_dispatch:

permissions:
contents: write

jobs:
publish_docs:
name: Publish Docs
get_cache_key:
runs-on: ubuntu-latest
outputs:
cache_key: ${{ steps.set_cache_key.outputs.cache_key }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- name: Set cache key
id: set_cache_key
run: echo "cache_key=docs-build-$(date --utc +'%Y-%m-%d_%H:%M:%S')" >> $GITHUB_OUTPUT

- name: Read cache
uses: actions/cache@v3
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
build_doxygen:
uses: hotosm/gh-workflows/.github/workflows/doxygen_build.yml@main
needs: [get_cache_key]
with:
cache_paths: |
docs/apidocs
cache_key: ${{ needs.get_cache_key.outputs.cache_key }}

- name: Install PDM
run: |
python3 -m pip install pdm
- name: Publish
run: |
pdm install -G docs --no-default
pdm run mkdocs gh-deploy --force
publish_docs:
uses: hotosm/gh-workflows/.github/workflows/mkdocs_build.yml@main
needs:
- get_cache_key
- build_doxygen
with:
image: ghcr.io/hotosm/fmtm-splitter:ci
cache_paths: |
docs/apidocs
cache_key: ${{ needs.get_cache_key.outputs.cache_key }}
23 changes: 5 additions & 18 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,11 @@ name: Publish to PyPi.org
on:
release:
types: [published]

env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
# Allow manual trigger (workflow_dispatch)
workflow_dispatch:

jobs:
publish_to_pypi:
name: Publish to PyPi
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install PDM
run: |
python3 -m pip install pdm
- name: Publish
run: |
pdm config repository.pypi.username "__token__"
pdm config repository.pypi.password "${PYPI_TOKEN}"
pdm publish
uses: hotosm/gh-workflows/.github/workflows/pypi_publish.yml@main
secrets:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
24 changes: 8 additions & 16 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ on:
push:
branches:
- "*"
paths:
# Workflow is triggered only if code or tests change
- "fmtm_splitter"
- "tests"
# Run tests on PR, prior to merge to main & development.
pull_request:
branches:
Expand All @@ -19,17 +15,13 @@ on:
jobs:
test:
runs-on: ubuntu-latest
environment:
name: "test"
container:
image: ghcr.io/hotosm/fmtm-splitter:ci

steps:
- uses: actions/checkout@v3

- name: Start CI Container
run: >
docker run -d --name fmtm_pytest
-v "$GITHUB_WORKSPACE/fmtm_splitter:/home/appuser/.local/lib/python3.10/site-packages/fmtm_splitter"
-v "$GITHUB_WORKSPACE/tests:/data/tests"
ghcr.io/hotosm/fmtm-splitter:ci
sleep infinity
- name: Run PyTest as appuser
run: docker exec fmtm_pytest gosu appuser pytest
- uses: actions/checkout@v4
- name: Run pytest
run: |
pytest

0 comments on commit df2cc31

Please sign in to comment.