From 742c31215fdb56822631d188fbc72d2557e6e637 Mon Sep 17 00:00:00 2001 From: Mohammad Mahdi Malmasi <=> Date: Fri, 19 Apr 2024 20:12:03 +0330 Subject: [PATCH] fix Build and Push Tag github action bugs --- .../workflows/build_and_push_python_codes.yml | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build_and_push_python_codes.yml b/.github/workflows/build_and_push_python_codes.yml index a23d976..5144997 100644 --- a/.github/workflows/build_and_push_python_codes.yml +++ b/.github/workflows/build_and_push_python_codes.yml @@ -21,6 +21,7 @@ jobs: uses: actions/checkout@v2 with: ref: ${{ github.ref }} + fetch-depth: 0 - name: Install dependencies run: | @@ -46,16 +47,27 @@ jobs: - name: Commit changes run: | - bash -c "if [[ ${{ github.ref }} == 'refs/tags/'* ]]; then export TAG_NAME=${{ github.ref }}; fi" - echo "Tag name: $TAG_NAME" - echo "payload: ${{ github.event.client_payload.tag_name }}" + if [[ "${{ github.ref }}" == refs/tags/* ]]; then + TAG_NAME="${GITHUB_REF#refs/tags/}" + echo "Tag name: $TAG_NAME" + echo "payload: ${{ github.event.client_payload.tag_name }}" + echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV + fi + LAST_COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s') cd destination-repo - git config user.email "m.mahdi.m79@gmail.com" - git config user.name "Mohammad Mahdi Malmasi" + LAST_GIT_COMMIT_NAME=$(git log -1 --pretty=format:'%an') + LAST_GIT_COMMIT_EMAIL=$(git log -1 --pretty=format:'%ae') + git config user.name "$LAST_GIT_COMMIT_NAME" + git config user.email "$LAST_GIT_COMMIT_EMAIL" git add . - git commit -m "Update for tag: $TAG_NAME" - git tag $TAG_NAME - git push --tags - git push origin master + if [ -z "$(git status --porcelain)" ]; then + echo "No changes to commit. push only new tag." + git tag $TAG_NAME + git push --follow-tags + else + git commit -m "$TAG_NAME | $LAST_COMMIT_MESSAGE" + git tag "$TAG_NAME" + git push --follow-tags + git push origin master env: TAG_NAME: ${{ github.event.client_payload.tag_name }}