Workflow file for this run
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: Deploy API image to Docker Hub | |
on: | |
release: | |
types: | |
- released | |
- prereleased | |
jobs: | |
deploy_to_docker_hub: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Check that tag and package versions match | |
run: | | |
PYPROJECT_VERSION=$(sed -n '3p' pyproject.toml | sed "s/version = //") | |
GITHUB_VERSION=${{ github.event.release.tag_name }} | |
if [[ "$PYPROJECT_VERSION" != "\"$GITHUB_VERSION\"" ]] | |
then | |
echo "pyproject.toml version $PYPROJECT_VERSION doesn't match GitHub version \"$GITHUB_VERSION\"" | |
exit 1 | |
fi | |
- name: Get release tag | |
id: current_release | |
run: | | |
CURRENT_RELEASE=${{ github.event.release.tag_name }} | |
echo "CURRENT_RELEASE=${CURRENT_RELEASE}" >> $GITHUB_ENV | |
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_RELEASE" | |
MAJOR_VERSION_NUMBER="${VERSION_PARTS[0]}" | |
echo "MAJOR_VERSION_NUMBER=${MAJOR_VERSION_NUMBER}" >> $GITHUB_ENV | |
echo "The current release is $CURRENT_RELEASE" | |
echo "The current major version number is $MAJOR_VERSION_NUMBER" | |
- name: Set pre-release suffix | |
if: ${{ github.event.release.prerelease }} | |
run: | | |
echo "TAG_SUFFIX=prerelease" >> $GITHUB_ENV | |
- name: Set release suffix | |
if: ${{ !github.event.release.prerelease }} | |
run: | | |
echo "TAG_SUFFIX=latest" >> $GITHUB_ENV | |
- name: Login to Docker Hub | |
id: docker_login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and Push current release and latest tag to Docker Hub | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: Dockerfile | |
tags: | | |
turingrc/rctab-api:${{ env.CURRENT_RELEASE }} | |
turingrc/rctab-api:${{ env.MAJOR_VERSION_NUMBER }}.${{ env.TAG_SUFFIX }} | |
push: true |