Modified workflow actions to generate latest tag #27
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: Mantis CLI Latest Release | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: phonepe/mantis | |
jobs: | |
build-and-push-image: | |
if: github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
actions: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Python and Git | |
uses: ./.github/actions/setup-python-and-git | |
with: | |
python-version: '3.9' | |
- name: Install Poetry | |
run: pip install poetry==1.4.2 | |
- name: Determine Current Version | |
run: | | |
latest_version=$(poetry version --short) | |
echo "LATEST_VERSION=$latest_version" >> $GITHUB_ENV | |
- name: Check if Git Tag Exists | |
id: git-tag | |
run: | | |
if git rev-parse "$latest_version" >/dev/null 2>&1; then | |
echo "Tag $latest_version already exists." | |
exit 0 | |
else | |
echo "Tag $latest_version does not exist." | |
echo "CREATE_TAG=true" >> $GITHUB_ENV | |
fi | |
- name: Create Git Tag | |
if: env.CREATE_TAG == 'true' | |
run: | | |
git tag -a "$LATEST_VERSION" -m "Release $LATEST_VERSION" | |
git push origin "$LATEST_VERSION" | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.LATEST_VERSION }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
labels: ${{ steps.meta.outputs.labels }} |