Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

caching - Semaphore CI - Environment Variables are Incorrect

I use semaphore CI for continuous integration, specifically for Feature tests and Specs in PHP and Ruby. I noticed a deviation from the documentation on caching in one of my projects. The documentation says:

The cache restore command that has zero arguments would lookup cachable elements and try to fetch them from the repository.

$ cache restore
==> Detecting project structure and storing it into the cache.

* Detected Gemfile.lock.
* Fetching 'vendor/bundle' directory with cache keys 'gems-your-branch-checksum,gems-master-,gems-your-branch-'.
...

The important part about that is the 3 cache keys:

gems-your-branch-checksum
gems-master-
gems-your-branch-

When I implemented the cache restore command and ran the job, this was the output I got:

* Detected Gemfile.lock.
* Fetching 'vendor/bundle' directory with cache keys 'gems-master-checksum,gems-master-,gems-master-'.
...

This job was not run against master, but a different branch, let's call it secondary. Notice the slight deviation on the branches:

gems-master-checksum (expected this to be gems-secondary-checksum)
gems-master- (this one is expected)
gems-master- (expected this to be gems-secondary)

For some reason, Semaphore thinks that my branch is master, not secondary. I did some more digging. You can manually specify Cache Keys using the following syntax:

cache restore gems-$SEMAPHORE_GIT_BRANCH-$(checksum Gemfile.lock)

But, when running this, it outputs

gems-master-checksum (expected gems-secondary-checksum)

I was able to eventually get it working with the other environment variable:

cache restore gems-$SEMAPHORE_GIT_PR_BRANCH-$(checksum Gemfile.lock)

gems-secondary-checksum

The documentation suggests that this shouldn't be the case:

SEMAPHORE_GIT_BRANCH
The value of the SEMAPHORE_GIT_BRANCH environment variable is the name of the GitHub branch that is used in the current job.
In builds triggered by a Pull Request the value of the SEMAPHORE_GIT_BRANCH is the name of the GitHub branch targeted by the Pull Request.

SEMAPHORE_GIT_PR_BRANCH
The value of the SEMAPHORE_GIT_PR_BRANCH environment variable is the name of the GitHub branch from which the Pull Request originated.

Has anyone seen this issue with Semaphore CI? It's not a critical issue, as there are workarounds, but I'm thinking there is an issue with my configuration somewhere, but I can't seem to find anything useful/related.

question from:https://stackoverflow.com/questions/65849848/semaphore-ci-environment-variables-are-incorrect

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...