Update version to "latest" in docker build #59
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 Push Docker Image | |
on: | |
push: | |
release: | |
types: | |
- created | |
branches: | |
- main | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Login to Docker Hub | |
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
- name: Login to GitHub Packages Docker Registry | |
run: echo "${{ secrets.GH_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin | |
- name: Build and push Docker image | |
run: | | |
if git rev-parse --verify "refs/tags/*" >/dev/null 2>&1; then | |
VERSION=$(git describe --tags --abbrev=0) | |
else | |
VERSION="latest" | |
fi | |
docker build -t ***/kode-pos:$VERSION . | |
docker push ***/kode-pos:$VERSION | |
- name: Set latest version | |
run: echo "LATEST_VERSION=latest" >> $GITHUB_ENV | |
- name: Set previous version | |
run: | | |
if git rev-parse --verify "refs/tags/*" >/dev/null 2>&1; then | |
PREVIOUS_VERSION=$(git describe --tags --abbrev=0) | |
echo "PREVIOUS_VERSION=$PREVIOUS_VERSION" >> $GITHUB_ENV | |
else | |
echo "PREVIOUS_VERSION=none" >> $GITHUB_ENV | |
fi | |
- name: Display version information | |
run: | | |
echo "Latest version: $LATEST_VERSION" | |
echo "Previous version: $PREVIOUS_VERSION" |