.github/workflows/build.yml #962
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
on: | |
schedule: | |
- cron: '30 2 * * 1' | |
pull_request: | |
workflow_dispatch: # Allow manual triggering | |
jobs: | |
versiontag: | |
runs-on: ubuntu-latest | |
if: github.ref != 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Check version tag | |
run: | | |
curl -f https://raw.githubusercontent.com/pvarki/docker-rasenmaeher-integration/main/version.yml -o /tmp/main_version.yml || touch /tmp/main_version.yml | |
diff /tmp/main_version.yml ./version.yml && exit 1 || exit 0 | |
apiunits: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
checks: write | |
strategy: | |
matrix: | |
python-version: ["3.11"] # , "3.12"] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install poetry | |
cd api && poetry install | |
- name: Prep docker | |
run: | | |
rm -rf api/tests/data/cfssl/* | |
rm -rf api/tests/data/ca_public/* | |
docker system prune --all --volumes --force | |
cd api/tests && docker compose -f docker-compose.yml build --pull | |
docker compose -f docker-compose.yml pull --ignore-buildable | |
docker compose -f docker-compose.yml up -d --wait || docker compose -f docker-compose.yml logs | |
docker compose -f docker-compose.yml down -v | |
- name: Test with pytest | |
run: | | |
cd api && poetry run py.test -v --junitxml=pytest-apiunit.xml tests/ | |
- name: Publish Test Report | |
uses: mikepenz/action-junit-report@v4 | |
if: success() || failure() # always run even if the previous step fails | |
with: | |
report_paths: 'api/pytest*.xml' | |
detailed_summary: true | |
check_name: 'api unit tests' | |
rmlocal: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
checks: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: install dependencies | |
id: install_dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r tests/requirements.txt | |
- name: pre-commit | |
id: pre_commit | |
run: | | |
export SKIP=no-commit-to-branch | |
source example_env.sh | |
pre-commit run --all-files | |
- name: docker compose build | |
id: compose_build | |
run: | | |
shopt -s expand_aliases | |
alias dcloc="docker compose -p rmlocal -f docker-compose-local.yml" | |
docker system prune --all --volumes --force | |
dcloc build --pull | |
dcloc pull --ignore-buildable | |
- name: docker compose cleanup | |
id: compose_clean_1 | |
run: | | |
shopt -s expand_aliases | |
alias dcloc="docker compose -p rmlocal -f docker-compose-local.yml" | |
alias dcdev="docker compose -p rmdev -f docker-compose-local.yml -f docker-compose-dev.yml" | |
dcloc down -v || true | |
dcdev down -v || true | |
- name: docker compose up first attempt | |
id: compose_up_first | |
run: | | |
shopt -s expand_aliases | |
alias dcloc="docker compose -p rmlocal -f docker-compose-local.yml" | |
dcloc up --wait || (dcloc logs && exit 1) | |
continue-on-error: true | |
- name: docker compose up second attempt | |
if: ${{ steps.compose_up_first.outcome == 'failure' }} | |
id: compose_up_second | |
run: | | |
shopt -s expand_aliases | |
alias dcloc="docker compose -p rmlocal -f docker-compose-local.yml" | |
dcloc up --wait || (dcloc logs && exit 1) | |
continue-on-error: true | |
- name: add test users | |
id: add_test_users | |
run: | | |
docker ps | |
docker exec rmlocal-rmapi-1 rasenmaeher_api addtestusers | |
docker exec rmlocal-rmapi-1 cat /etc/hosts | |
- name: Test with pytest | |
id: run_pytest | |
run: | | |
shopt -s expand_aliases | |
alias dcloc="docker compose -p rmlocal -f docker-compose-local.yml" | |
py.test -v --junitxml=pytest-rmlocal.xml tests/ || (dcloc logs && exit 1) | |
- name: Publish Test Report | |
uses: mikepenz/action-junit-report@v4 | |
if: success() || failure() # always run even if the previous step fails | |
with: | |
report_paths: '**/pytest*.xml' | |
detailed_summary: true | |
include_passed: true | |
check_name: 'rmlocal integration tests' | |
- name: docker compose cleanup | |
id: compose_clean_2 | |
if: ${{ !cancelled() }} | |
run: | | |
shopt -s expand_aliases | |
alias dcloc="docker compose -p rmlocal -f docker-compose-local.yml" | |
dcloc down -v || true | |
rmdev: | |
if: false | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
checks: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: install dependencies | |
id: install_dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r tests/requirements.txt | |
- name: pre-commit | |
id: pre_commit | |
run: | | |
export SKIP=no-commit-to-branch | |
source example_env.sh | |
pre-commit run --all-files | |
- name: docker compose build | |
id: compose_build | |
run: | | |
shopt -s expand_aliases | |
alias dcdev="docker compose -p rmdev -f docker-compose-local.yml -f docker-compose-dev.yml" | |
docker system prune --all --volumes --force | |
dcdev build --pull | |
dcdev pull --ignore-buildable | |
- name: docker compose cleanup | |
id: compose_clean_1 | |
run: | | |
shopt -s expand_aliases | |
alias dcdev="docker compose -p rmdev -f docker-compose-local.yml -f docker-compose-dev.yml" | |
alias dcloc="docker compose -p rmlocal -f docker-compose-local.yml" | |
dcdev down -v || true | |
dcloc down -v || true | |
- name: docker compose up first attempt | |
id: compose_up_first | |
run: | | |
shopt -s expand_aliases | |
alias dcdev="docker compose -p rmdev -f docker-compose-local.yml -f docker-compose-dev.yml" | |
dcdev up --wait || ( dcdev logs && exit 1 ) | |
continue-on-error: true | |
- name: docker compose up second attempt | |
if: ${{ steps.compose_up_first.outcome == 'failure' }} | |
id: compose_up_second | |
run: | | |
shopt -s expand_aliases | |
alias dcdev="docker compose -p rmdev -f docker-compose-local.yml -f docker-compose-dev.yml" | |
dcdev up --wait || ( dcdev logs && exit 1 ) | |
continue-on-error: true | |
- name: add test users | |
id: add_test_users | |
run: | | |
docker ps | |
docker exec rmdev-rmapi-1 /.venv/bin/rasenmaeher_api addtestusers | |
- name: Test with pytest | |
id: run_pytest | |
run: | | |
shopt -s expand_aliases | |
alias dcdev="docker compose -p rmdev -f docker-compose-local.yml -f docker-compose-dev.yml" | |
py.test -v --junitxml=pytest-rmdev.xml tests/ || ( dcdev logs && exit 1 ) | |
- name: Publish Test Report | |
uses: mikepenz/action-junit-report@v4 | |
if: success() || failure() # always run even if the previous step fails | |
with: | |
report_paths: '**/pytest*.xml' | |
detailed_summary: true | |
include_passed: true | |
check_name: 'rmdev integration tests' | |
- name: docker compose cleanup | |
id: compose_clean_2 | |
if: ${{ !cancelled() }} | |
run: | | |
shopt -s expand_aliases | |
alias dcdev="docker compose -p rmdev -f docker-compose-local.yml -f docker-compose-dev.yml" | |
dcdev down -v || true | |
build_and_publish: | |
runs-on: ubuntu-latest | |
needs: [apiunits, rmlocal] | |
strategy: | |
matrix: | |
extra_env: ["none", "date"] | |
steps: | |
- name: Log in to Docker Hub | |
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Fix ref slashes | |
run: | | |
echo REF_NO_SLASHES=$(echo "${{ github.ref_name }}" | sed 's/\//-/g') >> ${GITHUB_ENV} | |
- name: Set DOCKER_TAG_EXTRA if date | |
run: | | |
test "${{ matrix.extra_env }}" = "date" && echo "DOCKER_TAG_EXTRA=-$(date +%Y%m%d)" >> ${GITHUB_ENV} || true | |
cat ${GITHUB_ENV} | |
- name: Set DOCKER_TAG_EXTRA if not main | |
if: github.event.pull_request.merged != true | |
run: | | |
test "${{ github.ref }}" = "refs/heads/main" || echo "DOCKER_TAG_EXTRA=-$REF_NO_SLASHES" >> ${GITHUB_ENV} | |
cat ${GITHUB_ENV} | |
- name: Build takinit | |
run: | | |
source example_env.sh | |
docker compose build takinit | |
- name: push takinit | |
if: ${{ !env.ACT }} | |
run: | | |
source example_env.sh | |
docker compose push takinit | |
- name: Build main composition | |
run: | | |
source example_env.sh | |
docker compose build | |
- name: Push main composition | |
if: ${{ !env.ACT }} | |
run: | | |
source example_env.sh | |
docker compose push |