denys-meloshyn / bitrise-step-git-tag-project-version-and-build-number

This step will create Git tag with project version and build number
MIT License
4 stars 6 forks source link

Failure to push a tag doesn't mark the step as failed #25

Closed vadimbelyaev closed 12 months ago

vadimbelyaev commented 3 years ago

If the Bitrise project is configured with an SSH key that grants only read-only access to the remote Git repository, the git push command will fail, but the step will still be marked as successful.

Steps to reproduce:

  1. Create a new iOS project on Bitrise that uses a remote repository hosted at Gitlab or Bitbucket.
  2. During the project setup, opt-in to auto-add SSH keys (this will create a key that doesn't allow pushing to the remote)
  3. Add and configure the "Git tag project version and build number" step to the workflow
  4. Run the workflow

Expected result: "Git tag project version and build number" step fails and all subsequent steps that shouldn't execute if this step failed don't get executed.

Actual result: "Git tag project version and build number" finishes successfully (i.e. returns 0) but shows the git push error in the logs. All subsequent steps continue execution. For example:

+------------------------------------------------------------------------------+

| (10) git-tag-project-version-and-build-number@1                              |
+------------------------------------------------------------------------------+
| id: git-tag-project-version-and-build-number                                 |
| version: 1.0.10                                                              |
| collection: https://github.com/bitrise-io/bitrise-steplib.git                |
| toolkit: bash                                                                |
| time: 2021-01-13T09:54:37Z                                                   |
+------------------------------------------------------------------------------+
|                                                                              |
INFO[09:54:38]  * [OK] Step dependency (git) installed, available. 
Exctract version number from xcodeproj
New tag: v1.4.15
Warning: Permanently added 'bitbucket.org,104.192.141.1' (RSA) to the list of known hosts.
Unauthorized
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
|                                                                              |
+---+---------------------------------------------------------------+----------+
| ✓ | git-tag-project-version-and-build-number@1                    | 3.32 sec |
+---+---------------------------------------------------------------+----------+

Thank you so much for this useful plugin. Would be great to have this issue fixed, if possible.

denys-meloshyn commented 3 years ago

Hi @vadimbelyaev thank you for your feedback! I agree that it should fail in this case, but I'm not sure how to get status from git push command. In case you know how to detect a fail please tell me 🙂

vadimbelyaev commented 3 years ago

@denys-meloshyn, thank you for the quick reaction!

I believe the git push command will return a non-zero exit code if it fails and zero if it succeeds. I'm not an expert in shell scripting and I don't know the best way to program it, but I know that $? will return the error code of the last executed command. Alternatively, there should be a way to just save the exit code to a variable and check its value later.

Hope this helps and appreciate your efforts!