Update workflow #77
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: | |
branches: | |
- master | |
tags: | |
- '*' | |
jobs: | |
test_api: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Test | |
run: docker-compose -f $GITHUB_WORKSPACE/zoonavigator-api/docker-compose.test.yml up --exit-code-from=sut | |
test_web: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Test | |
run: docker-compose -f $GITHUB_WORKSPACE/zoonavigator-web/docker-compose.test.yml up --exit-code-from=sut | |
setup_env: | |
runs-on: ubuntu-latest | |
needs: | |
- test_api | |
- test_web | |
outputs: | |
app_version: ${{ steps.set_vars.outputs.app_version }} | |
docker_tag: ${{ steps.set_vars.outputs.docker_tag }} | |
docker_image: ${{ steps.set_vars.outputs.docker_image }} | |
snap_channel: ${{ steps.set_vars.outputs.snap_channel }} | |
docs_url: ${{ steps.set_vars.outputs.docs_url }} | |
vcs_ref: ${{ steps.set_vars.outputs.vcs_ref }} | |
build_date: ${{ steps.set_vars.outputs.build_date }} | |
steps: | |
- id: set_vars | |
name: Set variables | |
run: | | |
tag="${GITHUB_REF_NAME#v}" | |
# is this a semver release? | |
if [[ "${tag}" =~ ^[0-9]+(\.[0-9]+){2,3}$ ]]; | |
then | |
app_version="${tag}" | |
snap_channel="stable" | |
docker_tag="${tag}" | |
docs_url="https://zoonavigator.elkozmon.com/en/${tag}" | |
else | |
app_version="latest-${GITHUB_SHA::12}" | |
snap_channel="beta" | |
docker_tag="unstable" | |
docs_url="https://zoonavigator.elkozmon.com/en/latest" | |
fi | |
# set image name | |
docker_image="elkozmon/zoonavigator" | |
echo "app_version=${app_version}" >> "$GITHUB_OUTPUT" | |
echo "docker_tag=${docker_tag}" >> "$GITHUB_OUTPUT" | |
echo "docker_image=${docker_image}" >> "$GITHUB_OUTPUT" | |
echo "snap_channel=${snap_channel}" >> "$GITHUB_OUTPUT" | |
echo "docs_url=${docs_url}" >> "$GITHUB_OUTPUT" | |
echo "vcs_ref=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" | |
echo "build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_OUTPUT" | |
build_docker: | |
runs-on: ubuntu-latest | |
needs: | |
- setup_env | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: ${{ github.workspace }}/build/docker/Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
push: false | |
outputs: type=local,dest=out | |
tags: ${{ needs.setup_env.outputs.docker_image }}:${{ needs.setup_env.outputs.docker_tag }} | |
build-args: APP_VERSION=${{ needs.setup_env.outputs.app_version }},DOCS_URL=${{ needs.setup_env.outputs.docs_url }},VCS_REF=${{ needs.setup_env.outputs.vcs_ref }},BUILD_DATE=${{ needs.setup_env.outputs.build_date }} | |
- name: Package jars | |
run: tar -cvzf jars.tar.gz -C out/linux_amd64/app lib extra | |
- name: Upload jars | |
uses: actions/upload-artifact@v1 | |
with: | |
name: jars | |
path: jars.tar.gz | |
build_snap: | |
runs-on: ubuntu-latest | |
needs: | |
- setup_env | |
- build_docker | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download jars | |
uses: actions/download-artifact@v1 | |
with: | |
name: jars | |
- name: Prepare source | |
run: | | |
echo "$APP_VERSION" \ | |
> ${GITHUB_WORKSPACE}/build/snap/local/version | |
tar \ | |
-xvf ${GITHUB_WORKSPACE}/jars/jars.tar.gz \ | |
-C ${GITHUB_WORKSPACE}/build/snap/local | |
- id: build_snap | |
name: Build Snap | |
uses: snapcore/action-build@v1 | |
with: | |
path: build/ | |
- name: Publish Snap | |
uses: snapcore/action-publish@v1 | |
env: | |
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }} | |
with: | |
snap: ${{ steps.build_snap.outputs.snap }} | |
release: ${{ needs.setup_env.outputs.snap_channel }} | |
cleanup: | |
runs-on: ubuntu-latest | |
needs: | |
- build_docker | |
- build_snap | |
if: ${{ always() }} | |
steps: | |
- name: Delete artifacts | |
uses: geekyeggo/delete-artifact@v1 | |
with: | |
name: jars |