Skip to content

Commit

Permalink
Artifact + Matrix - 10
Browse files Browse the repository at this point in the history
Added another TODO.

evious Push event triggers run failed

Error occurred in GitHub actions git add, commit, push step.
If file with no changes operated upon, it leaves an error:
“nothing to commit, working tree clean
Error: Process completed with exit code 1.”

Need to fix.

——

Quick fix is to make changes to .env file only if workflow_dispatch event is the trigger.
Don’t do anything for push event.
So, in case anyone modifies .env file on their own by using their own timestamp during testing, and pushes it as a part of their PR, then Shankari will have to ask them to revert the changes.
Else, their custom timestamp will make it to the repo code base.

Found something:
https://www.reddit.com/r/github/comments/ju3ipr/commit_from_github_action_only_when_changes_exist/

It should work but there’s a drawback of using “exit 0” - it will mask all errors generated during “git commit”.
This is bad and we won’t be able to see the reason why something wrong happened as the workflow would be shown as successful with a green tick.

Found a solution with git diff:
https://github.com/simonw/til/blob/main/github-actions/commit-if-file-changed.md

$ git diff --quiet || (git add README.md && git commit -m "Updated README")

However, I won’t be able to log any message saying that no changes to commit, tag not modified.
Hence, will possibly use just “git diff —quiet” with an if-else block.

Expected results:
- Push event triggers workflow.
- It writes DOCKER_IMAGE_TAG_1 fetched from last successful completed run to .env file.
- It sees that there is a difference in the latest committed .env file in the dashboard repo which includes older timestamp.
- Hence it runs git commit part of the script to reset to latest server timestamp.
  • Loading branch information
Mahadik, Mukul Chandrakant authored and Mahadik, Mukul Chandrakant committed May 3, 2024
1 parent 352c8ae commit d98f75c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DOCKER_IMAGE_TAG=2024-05-03--14-37
DOCKER_IMAGE_TAG=2024-05-02--16-40
11 changes: 8 additions & 3 deletions .github/workflows/image_build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
with:
name: docker-image-tag
# TODO: Create a token with basic repo permissions
# TODO: Change user / organization to emission instead of MukuFlash03
github-token: ${{ secrets.GH_PAT_TAG }}
repository: MukuFlash03/e-mission-server
run-id: ${{ env.RUN_ID }}
Expand Down Expand Up @@ -133,9 +134,13 @@ jobs:
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .env
git commit -m "Updated docker image tag in .env to the latest timestamp"
git push origin
if git diff --quiet; then
echo "Latest timestamp already present in .env file, no changes to commit"
else
git add .env
git commit -m "Updated docker image tag in .env file to the latest timestamp"
git push origin
fi
- name: docker login
run: | # log into docker hub account
Expand Down

0 comments on commit d98f75c

Please sign in to comment.