Hi folks! I’m having troubles to implement some kind of pipeline when a pre-existing tag is already “linked” to a commit.
First of all, this is my config (let’s imagine for now that those scripts are just an ‘echo’ saying main/staging/prod):
version: 2.1
jobs:
main:
docker:
- image: cimg/base:stable
steps:
- checkout
- run: "scripts/main.sh"
staging:
docker:
- image: cimg/base:stable
steps:
- checkout
- run: "scripts/staging.sh"
prod:
docker:
- image: cimg/base:stable
steps:
- checkout
- run: "scripts/prod.sh"
workflows:
pointers:
jobs:
- prod:
filters:
tags:
only: PROD
branches:
ignore: /.*/
developing:
jobs:
- main:
filters:
branches:
only: main
- staging:
filters:
branches:
only: staging
I’ve already read about this topic, however, I think that my situation is slight different because I push the pre-existing tag to another commit.
So… enough words, let me show you what I’m saying:
- I create a new branch
$ git branch test/circleci origin/main
Branch 'test/circleci' set up to track remote branch 'main' from 'origin'.
$ git checkout test/circleci
Switched to branch 'test/circleci'
Your branch is up to date with 'origin/main'.
$ git add . && git commit -m "Update docs"
[test/circleci ebac2e1] Update docs
1 file changed, 3 insertions(+), 1 deletion(-)
$ git push origin test/circleci --set-upstream
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 295 bytes | 295.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote:
remote: Create a pull request for 'test/circleci' on GitHub by visiting:
remote: https://github.com/fjinkis/git/pull/new/test/circleci
remote:
To github.com:fjinkis/git.git
* [new branch] test/circleci -> test/circleci
Branch 'test/circleci' set up to track remote branch 'test/circleci' from 'origin'.
- I merge that branch to staging using GitHub and that triggers the workflow ‘developing’ and executes the script ‘staging.sh’
-
After that, I merge from staging to main, the workflow ‘developing’ runs and the script pushes the PROD tag to the origin/HEAD
-
Because of the previous step, pushing the PROD tag triggers the workflow ‘pointers’ that executes ‘prod.sh’ (which is fine!)
- I decide to move PROD tag to other commit (or tag, it’s the same) but that action doesn’t trigger the workflow
$ git fetch --all --prune
remote: Enumerating objects: 2, done.
remote: Counting objects: 100% (2/2), done.
remote: Compressing objects: 100% (2/2), done.
Unpacking objects: 100% (2/2), 1.19 KiB | 1.19 MiB/s, done.
remote: Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
From github.com:fjinkis/git
cf0f0d3..9350b43 main -> origin/main
8e0997d..a46d256 staging -> origin/staging
* [new tag] PROD -> PROD
* [new tag] v1.0.4 -> v1.0.4
$ git pull
Updating cf0f0d3..9350b43
Fast-forward
README.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
$ git tag -d PROD
Deleted tag 'PROD' (was 9350b43)
$ git push --delete origin PROD
To github.com:fjinkis/git.git
- [deleted] PROD
$ git tag PROD v1.0.2
$ git push origin PROD
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:fjinkis/git.git
* [new tag] PROD -> PROD
- I create a new branch and merge it directly to main to check if the ‘pointers’ workflow runs
$ git branch --merged
* main
staging
test/circleci
$ git branch -d test/circleci
Deleted branch test/circleci (was ebac2e1).
$ git branch test/circleci-retry origin/main
Branch 'test/circleci-retry' set up to track remote branch 'main' from 'origin'.
$ git checkout test/circleci-retry
Switched to branch 'test/circleci-retry'
Your branch is up to date with 'origin/main'.
$ git add . && git commit -m "Update docs"
[test/circleci-retry 9b9dc70] Update docs
1 file changed, 2 deletions(-)
$ git push origin test/circleci-retry --set-upstream
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 266 bytes | 266.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote:
remote: Create a pull request for 'test/circleci-retry' on GitHub by visiting:
remote: https://github.com/fjinkis/git/pull/new/test/circleci-retry
remote:
To github.com:fjinkis/git.git
* [new branch] test/circleci-retry -> test/circleci-retry
Branch 'test/circleci-retry' set up to track remote branch 'test/circleci-retry' from 'origin'.
Tadaaaa! The PROD tag triggered the workflow again! So my question is, what is the difference in this case? Because the main.sh does exactly the same than me:
TAG=$(git tag -l | tail -n1)
git tag -d $TAG && git push --delete origin $TAG
git tag -d PROD && git push --delete origin PROD
git tag $TAG origin/main && git tag PROD origin/main && git push --tags
I hope these screenshots and terminal snippets help to you all!
Let me know what you think and thanks in advance!!