adapted test, and added explanatory comment #435
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: Unittest xcube-geodb | |
on: | |
workflow_dispatch: | |
push: | |
release: | |
types: [published] | |
env: | |
APP_NAME: xcube-geodb | |
ORG_NAME: bcdev | |
# Skip PSQL tests in unittests. Can make sense if you have e.g. installation issues with postgis | |
SKIP_PSQL_TESTS: "0" | |
# When developing jobs it could make sense to switch off the test sections as they take time | |
# Unfortunately, you cannot set an if statement on job level. Hence, these variables are used in each step | |
# of a unittest/nb-test job. | |
RUN_UNITTESTS: "1" | |
# todo - switch the notebook tests back on after xcube-hub has been replaced | |
# Currently, the notebooks under test use xcube-hub, which uses an HS256 key to | |
# authenticate at PostGREST. The switch from xcube-hub to a Keycloak-based solution | |
# enforces the use of an RS256 key. Therefore, dev-PostGREST is already configured | |
# with an RS256 key, but as we do not want to change xcube-hub in that respect, we | |
# switch off the notebook-tests. | |
RUN_NB_TESTS: "0" | |
# Determines whether the dev branch ouy are working on shall have a docker image (default 0) | |
DOCKER_BUILD_MY_BRANCH: "0" | |
jobs: | |
unittest: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash -l {0} | |
steps: | |
# Print info | |
- run: | | |
echo "Skipping SQL tests: ${{ env.SKIP_PSQL_TESTS }}" | |
echo "RUN_UNITTESTS: ${{ env.RUN_UNITTESTS }}" | |
- uses: actions/checkout@v2 | |
- uses: conda-incubator/setup-miniconda@v2 | |
if: ${{ env.RUN_UNITTESTS == '1' }} | |
with: | |
channels: conda-forge | |
auto-update-conda: true | |
activate-environment: xcube-geodb | |
environment-file: etc/environment-workflow.linux-64.lock | |
- run: | | |
conda info | |
conda list | |
conda config --show-sources | |
conda config --show | |
printenv | sort | |
- name: setup xcube-geodb | |
if: ${{ env.RUN_UNITTESTS == '1' }} | |
run: | | |
pip install gsconfig-py3 testing.postgresql requests_mock | |
python setup.py develop | |
- name: unittest-xcube-geodb | |
if: ${{ env.RUN_UNITTESTS == '1' }} | |
run: | | |
export SKIP_PSQL_TESTS=${{ env.SKIP_PSQL_TESTS }} | |
pip install pytest | |
pip install pytest-cov | |
pytest --cov=./ --cov-report=xml | |
- uses: codecov/codecov-action@v4 | |
if: ${{ env.RUN_UNITTESTS == '1' }} | |
with: | |
fail_ci_if_error: true | |
verbose: true | |
token: ${{ secrets.CODECOV_TOKEN }} | |
# Testing notebooks that come with the xcube-geodb repo | |
nb-test: | |
runs-on: ubuntu-latest | |
env: | |
GEODB_API_SERVER_URL: ${{ secrets.GEODB_API_SERVER_URL }} | |
GEODB_AUTH_CLIENT_ID: ${{ secrets.GEODB_AUTH_CLIENT_ID }} | |
GEODB_AUTH_CLIENT_SECRET: ${{ secrets.GEODB_AUTH_CLIENT_SECRET }} | |
GEODB_AUTH_DOMAIN: ${{ secrets.GEODB_AUTH_DOMAIN }} | |
GEOSERVER_SERVER_URL: ${{ secrets.GEOSERVER_SERVER_URL }} | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: conda-incubator/setup-miniconda@v2 | |
if: ${{ env.RUN_NB_TESTS == '1' }} | |
with: | |
channels: conda-forge | |
activate-environment: xcube-geodb | |
environment-file: etc/environment-workflow.linux-64.lock | |
- name: setup xcube-geodb | |
if: ${{ env.RUN_NB_TESTS == '1' }} | |
shell: bash -l {0} | |
run: | | |
conda info | |
conda list | |
python setup.py develop | |
- name: install papermill | |
if: ${{ env.RUN_NB_TESTS == '1' }} | |
shell: bash -l {0} | |
run: pip install papermill[all] | |
- name: test-notebooks | |
if: ${{ env.RUN_NB_TESTS == '1' }} | |
shell: bash -l {0} | |
working-directory: notebooks | |
run: | | |
for nb in $(ls *.ipynb | grep -v publish_collection) | |
do | |
papermill $nb $(basename -s .ipynb $nb)_out.ipynb | |
done | |
update-version-deployment: | |
env: | |
PUSH: 1 | |
runs-on: ubuntu-latest | |
name: update-tag | |
needs: [unittest, nb-test] | |
steps: | |
- name: Get installation token | |
id: get_installation_token | |
uses: tibdex/github-app-token@v1 | |
with: | |
app_id: ${{ secrets.TOKEN_PROVIDER_APP_ID }} | |
private_key: ${{ secrets.TOKEN_PROVIDER_KEY }} | |
repository: bc-org/k8s-configs | |
# the installationId of the GitHub app we are using | |
installationId: 36950178 | |
- name: git-checkout | |
uses: actions/checkout@v2 | |
# Clone k8s-config into path 'k8s' | |
- name: checkout-k8s | |
run: | | |
mkdir k8s | |
cd k8s | |
git clone https://x-access-token:${{ steps.get_installation_token.outputs.token }}@github.com/bc-org/k8s-configs.git | |
# Get the release tag (or main on push) | |
- name: get-release-tag | |
id: release | |
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} | |
# Determine the deployment phase | |
- name: deployment-phase | |
id: deployment-phase | |
uses: bc-org/gha-determine-phase@v0.1 | |
with: | |
event_name: ${{ github.event_name }} | |
tag: ${{ steps.release.outputs.tag }} | |
- name: get-hash | |
id: get-hash | |
run: | | |
HASH=$(skopeo inspect docker://quay.io/bcdev/${{ env.APP_NAME }}-lab:${{ steps.release.outputs.tag }} | jq '.Digest') | |
if [[ "$HASH" == *"sha256"* ]]; then | |
echo ::set-output name=hash::$HASH | |
else | |
echo "No hash present. Using none as hash. This will use the version tag instead for deployment." | |
echo ::set-output name=hash::none | |
fi | |
- name: info | |
run: | | |
echo "Event: ${{ github.event_name }}" | |
echo "Deployment Stage: ${{ steps.deployment-phase.outputs.phase }}" | |
echo "Release Tag: ${{ steps.release.outputs.tag }}" | |
echo "Deployment Release Tag: ${{ steps.deployment-phase.outputs.tag }}" | |
echo "Deployment Digest: ${{ steps.get-hash.outputs.hash }}" | |
- name: set-version-tag | |
uses: bc-org/update-application-version-tags@main | |
with: | |
app: ${{ env.APP_NAME }} | |
phase: ${{ steps.deployment-phase.outputs.phase }} | |
delimiter: ' ' | |
tag: ${{ steps.deployment-phase.outputs.tag }} | |
hash: ${{ steps.get-hash.outputs.hash }} | |
working-directory: "./k8s/k8s-configs/${{ env.APP_NAME }}-jh/helm" | |
- name: cat-result | |
working-directory: "./k8s/k8s-configs/${{ env.APP_NAME }}-jh/helm" | |
run: | | |
head values-dev.yaml | |
head values-stage.yaml | |
# No production deployment at the moment | |
# head values-prod.yaml | |
- name: Pushes to another repository | |
# Don't run if run locally and should be ignored | |
if: ${{ steps.deployment-phase.outputs.phase != 'ignore' && !env.ACT }} | |
run: | | |
cd ./k8s/k8s-configs | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
git commit -am "${{ github.event.release }}. Set version to ${{ steps.release.outputs.tag }}" || true | |
git remote set-url origin https://x-access-token:${{ steps.get_installation_token.outputs.token }}@github.com/bc-org/k8s-configs.git | |
git push origin main |