Skip to content

LATEST_RELEASE always incorrect when feature branch naming conventions followed #30

@ctorgalson

Description

@ctorgalson

According to the LGD branch naming conventions, feature branches should have names like this:

feature/2.x/123-nice-new-thing

But the test-module.yml step "Get the latest tagged release for branch version" uses parameter expansions to return everything before the first . in the current branch name. With a branch like the sample feature branch above, the result is:

feature/2

This causes the github API request to return an empty result since there will be no tag matching the branch name.

I'm not 100% certain this is affecting workflows on github.com. But it causes workflows run locally to fail with errors like these (the as 1 is the symptom):

Updating dependencies                                 
| Your requirements could not be resolved to an installable set of packages.
| 
|   Problem 1
|     - localgovdrupal/localgov is locked to version 3.2.x-dev and an update of this package was not requested.
|     - localgovdrupal/localgov 3.2.x-dev requires localgovdrupal/localgov_step_by_step ^2.1.0 -> found localgovdrupal/localgov_step_by_step[2.1.0, ..., 2.x-dev] but it conflicts with your root composer.json require (dev-feature/2.x/72-module-javascript-needs-improvement as 1).

Here's a short bash script demonstrating the issue:

#!/usr/bin/env bash
#
# To use:
# 
#   1. retrieve a github auth token using e.g. `gh auth token`
#   2. save this script as e.g. `release-test.sh`
#   3. run the script using `GH_TOKEN=yourtokenvalue ./release-test.sh`

GIT_BASE_PASS="2.x/branch-name"
GIT_BASE_FAIL="feature/2.x/123-nice-new-thing"
GITHUB_REPOSITORY="localgovdrupal/localgov_step_by_step"

LATEST_RELEASE_PASS=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/${GIT_BASE_PASS%%.*} | grep -Po '(?<=refs/tags/)[^"]+' | tail -1)
LATEST_RELEASE_FAIL=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/${GIT_BASE_FAIL%%.*} | grep -Po '(?<=refs/tags/)[^"]+' | tail -1)

echo
echo

printf "PASS (%s): %s\n" $GIT_BASE_PASS $LATEST_RELEASE_PASS
printf "FAIL (%s): %s\n" $GIT_BASE_FAIL $LATEST_RELEASE_FAIL

The fix for this is probably to forgo parameter expansion in this instance and use an additional grep call to define a var like BRANCH_VERSION etc, and use that in place of ${GIT_BASE%%.*} in the script.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions