Merge pull request #77 from Oceans-1876/main #37
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: Build and publish the API docker image on Github Container Registry | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
- develop | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout source code | |
- name: Check out source code | |
uses: actions/checkout@v4 | |
# Calculate some variables that are used later | |
- name: Version information | |
run: | | |
if [ "${{ github.event.release.target_commitish }}" != "" ]; then | |
BRANCH="${{ github.event.release.target_commitish }}" | |
elif [[ $GITHUB_REF =~ pull ]]; then | |
BRANCH="$(echo $GITHUB_REF | sed 's#refs/pull/\([0-9]*\)/merge#PR-\1#')" | |
else | |
BRANCH=${GITHUB_REF##*/} | |
fi | |
echo "GITHUB_BRANCH=${BRANCH}" >> $GITHUB_ENV | |
if [ "$BRANCH" == "main" ]; then | |
version=$(awk -F= '/^version/ { print $2}' pyproject.toml | sed 's/[ "]//g') | |
tags="latest" | |
oldversion="" | |
while [ "${oldversion}" != "${version}" ]; do | |
oldversion="${version}" | |
tags="${tags},${version}" | |
version=${version%.*} | |
done | |
echo "VERSION=${version}" >> $GITHUB_ENV | |
echo "TAGS=${tags}" >> $GITHUB_ENV | |
elif [ "$BRANCH" == "develop" ]; then | |
echo "VERSION=develop" >> $GITHUB_ENV | |
echo "TAGS=develop" >> $GITHUB_ENV | |
else | |
echo "VERSION=testing" >> $GITHUB_ENV | |
echo "TAGS=${BRANCH}" >> $GITHUB_ENV | |
fi | |
# build image | |
- name: Build image | |
uses: elgohr/[email protected] | |
env: | |
BRANCH: ${{ env.GITHUB_BRANCH }} | |
VERSION: ${{ env.VERSION }} | |
BUILDNUMBER: ${{ github.run_number }} | |
GITSHA1: ${{ github.sha }} | |
with: | |
name: Oceans-1876/challenger-api | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
registry: ghcr.io | |
tags: "${{ env.TAGS }}" | |
buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1 | |
dockerfile: docker/Dockerfile | |
- name: Deploy to prod server | |
uses: joelwmale/webhook-action@master | |
env: | |
BRANCH: ${{ env.GITHUB_BRANCH }} | |
if: env.GITHUB_BRANCH == 'main' | |
with: | |
url: ${{ secrets.WEBHOOK_URL_PROD }} | |
headers: '{"X-Hub-Signature": "${{ secrets.WEBHOOK_SECRET_PROD }}"}' | |
- name: Deploy dev server | |
uses: joelwmale/webhook-action@master | |
env: | |
BRANCH: ${{ env.GITHUB_BRANCH }} | |
if: env.GITHUB_BRANCH == 'develop' | |
with: | |
url: ${{ secrets.WEBHOOK_URL_DEV }} | |
headers: '{"X-Hub-Signature": "${{ secrets.WEBHOOK_SECRET_DEV }}"}' |