#49 - allow for property files other than gradle.properties
diff --git a/post-release/README.md b/post-release/README.md
index 4201b2c..024ed2b 100644
--- a/post-release/README.md
+++ b/post-release/README.md
@@ -22,7 +22,7 @@
1. Creating a branch of named like `merge-back-TAGNAME` that will:
* Include the tag changes to prevent orphaned changes.
- * Include changing the version in `gradle.properties` or `version` to the next version.
+ * Include changing the `projectVersion` or `version` property in `gradle.properties` to the next version.
2. Optionally closing the current milestone associated with the release.
3. Optionally running an additional script as part of the close process to transform files in the repository.
@@ -38,7 +38,8 @@
## Environment Variables
* (optional) `RELEASE_VERSION` - The version of the release being closed. If not set, it will be derived from the `GITHUB_REF`, which as part of a release will be the tag name.
* (optional) `RELEASE_TAG_PREFIX` - The prefix of the release tag. If not set, it will default to `v` (e.g., `v1.0.0`).
-* (optional) `RELEASE_SCRIPT_PATH` - An optional path to a custom shell script that will be executed after the version replacement in `gradle.properties`, but prior to commiting the project changes.
+* (optional) `PROPERTY_FILE_NAME` - defaults to `gradle.properties`, the property file containing the version property to update
+* (optional) `RELEASE_SCRIPT_PATH` - An optional path to a custom shell script that will be executed after the version replacement in property file defined by `PROPERTY_FILE_NAME`, but prior to commiting the project changes.
## Example Usage
diff --git a/post-release/entrypoint.sh b/post-release/entrypoint.sh
index 191053f..98157b7 100755
--- a/post-release/entrypoint.sh
+++ b/post-release/entrypoint.sh
@@ -76,6 +76,7 @@
set_value_or_error "${GITHUB_API_URL}" "" "GITHUB_API_URL"
set_value_or_error "${RELEASE_VERSION}" "${GITHUB_REF#refs/*/}" "RELEASE_VERSION"
set_value_or_error "${RELEASE_TAG_PREFIX}" "v" "RELEASE_TAG_PREFIX"
+set_value_or_error "${PROPERTY_FILE_NAME}" "gradle.properties" "PROPERTY_FILE_NAME"
echo "::group::Determine release version"
if [[ ! "${RELEASE_VERSION}" =~ ^(${RELEASE_TAG_PREFIX})?[^.]+\.[^.]+\.[^.]+$ ]]; then
@@ -130,11 +131,11 @@
echo "::group::Add commit to update to next version"
echo "Setting new snapshot version"
-sed -i "s/^projectVersion\=.*$/projectVersion\=${NEXT_VERSION}-SNAPSHOT/" gradle.properties
-sed -i "s/^version\=.*$/version\=${NEXT_VERSION}-SNAPSHOT/" gradle.properties
-cat gradle.properties
+sed -i "s/^projectVersion\=.*$/projectVersion\=${NEXT_VERSION}-SNAPSHOT/" "${PROPERTY_FILE_NAME}"
+sed -i "s/^version\=.*$/version\=${NEXT_VERSION}-SNAPSHOT/" "${PROPERTY_FILE_NAME}"
+cat "${PROPERTY_FILE_NAME}"
printf "\n"
-git add gradle.properties
+git add "${PROPERTY_FILE_NAME}"
if [[ -n "${RELEASE_SCRIPT_PATH}" && -x "${GITHUB_WORKSPACE}/${RELEASE_SCRIPT_PATH}" ]]; then
echo "Executing additional release script at ${GITHUB_WORKSPACE}/${RELEASE_SCRIPT_PATH}"
diff --git a/pre-release/README.md b/pre-release/README.md
index ef0da99..e00c871 100644
--- a/pre-release/README.md
+++ b/pre-release/README.md
@@ -33,7 +33,8 @@
## Environment Variables
* (required) `RELEASE_VERSION` - The version of the release being created.
* (optional) `RELEASE_TAG_PREFIX` - The prefix of the release tag. If not set, it will default to `v` (e.g., `v1.0.0`).
-* (optional) `RELEASE_SCRIPT_PATH` - An optional path to a custom shell script that will be executed after the version replacement in `gradle.properties`, but prior to commiting the project changes.
+* (optional) `PROPERTY_FILE_NAME` - defaults to `gradle.properties`, the property file containing the version property to update
+* (optional) `RELEASE_SCRIPT_PATH` - An optional path to a custom shell script that will be executed after the version replacement in the property file defined by `PROPERTY_FILE_NAME`, but prior to commiting the project changes.
## Example Usage
diff --git a/pre-release/entrypoint.sh b/pre-release/entrypoint.sh
index 35bcb66..c4353c6 100755
--- a/pre-release/entrypoint.sh
+++ b/pre-release/entrypoint.sh
@@ -83,6 +83,7 @@
set_value_or_error "${RELEASE_URL}" `cat $GITHUB_EVENT_PATH | jq '.release.url' | sed -e 's/^"\(.*\)"$/\1/g'` "RELEASE_URL"
set_value_or_error "${GIT_USER_NAME}" "${GITHUB_ACTOR}" "GIT_USER_NAME"
set_value_or_error "${GITHUB_WORKSPACE}" "." "GIT_SAFE_DIR"
+set_value_or_error "${PROPERTY_FILE_NAME}" "gradle.properties" "PROPERTY_FILE_NAME"
echo "Configuring git"
git config --global --add safe.directory "${GIT_SAFE_DIR}"
@@ -93,12 +94,12 @@
echo "::group::Updating Project Version"
git checkout "${RELEASE_TAG_PREFIX}${RELEASE_VERSION}"
-echo "Setting release version in gradle.properties"
-sed -i "s/^projectVersion\=.*$/projectVersion\=${RELEASE_VERSION}/" gradle.properties
-sed -i "s/^version\=.*$/version\=${RELEASE_VERSION}/" gradle.properties
-cat gradle.properties
+echo "Setting release version in ${PROPERTY_FILE_NAME}"
+sed -i "s/^projectVersion\=.*$/projectVersion\=${RELEASE_VERSION}/" "${PROPERTY_FILE_NAME}"
+sed -i "s/^version\=.*$/version\=${RELEASE_VERSION}/" "${PROPERTY_FILE_NAME}"
+cat "${PROPERTY_FILE_NAME}"
echo "\n"
-git add gradle.properties
+git add "${PROPERTY_FILE_NAME}"
echo "::endgroup::"
if [[ -n "${RELEASE_SCRIPT_PATH}" && -x "${GITHUB_WORKSPACE}/${RELEASE_SCRIPT_PATH}" ]]; then
diff --git a/tests/src/test/groovy/org/apache/grails/github/PostReleaseSpec.groovy b/tests/src/test/groovy/org/apache/grails/github/PostReleaseSpec.groovy
index 4a00f38..2abb247 100644
--- a/tests/src/test/groovy/org/apache/grails/github/PostReleaseSpec.groovy
+++ b/tests/src/test/groovy/org/apache/grails/github/PostReleaseSpec.groovy
@@ -83,6 +83,65 @@
action.close()
}
+ def "success - different property file name"() {
+ given:
+ Network net = Network.newNetwork()
+
+ and:
+ GitHubVersion release = new GitHubVersion(version: '7.0.0-RC1', tagName: 'v7.0.0-RC1', targetBranch: '7.0.x', targetVersion: '7.0.0-SNAPSHOT')
+ GitHubDockerAction action = new GitHubDockerAction('post-release', release, new GitHubCliMock())
+
+ GitHubRepoMock gitRepo = new GitHubRepoMock(action.workspacePath, net)
+ gitRepo.init()
+ gitRepo.populateRepository('7.0.0-SNAPSHOT', 'v7.0.0-RC1', ['7.0.x'], [
+ 'README.md' : '# demo\n',
+ 'foo.properties': "projectVersion=7.0.0-SNAPSHOT\n"
+ ])
+ gitRepo.storeFiles(['foo.properties': "projectVersion=7.0.0-RC1\n"], 'v7.0.0-RC1')
+ gitRepo.stageRepositoryForAction('v7.0.0-RC1', true)
+
+ and:
+ def env = action.getDefaultEnvironment()
+ env['GH_MOCK_PR_CREATE'] = 'create'
+ env['PROPERTY_FILE_NAME'] = 'foo.properties'
+
+ and:
+ action.createContainer(env, net)
+
+ when:
+ action.runAction()
+
+ then:
+ action.actionExitCode == 0L
+ action.actionLogs
+
+ and: 'release version'
+ action.getActionGroupLogs('Determine release version') == 'Release Version: 7.0.0-RC1'
+
+ and: 'next version'
+ action.getActionGroupLogs('Determine next version') == 'Next Version: 7.0.0'
+
+ and: 'target branch'
+ action.getActionGroupLogs('Determine target merge branch').contains('Target Branch is refs/heads/v7.0.0-RC1')
+ action.getActionGroupLogs('Determine target merge branch').contains('Pruned Target Branch is v7.0.0-RC1')
+
+ and: 'project version reverted'
+ action.workspacePath.resolve('foo.properties').toFile().text.contains("projectVersion=7.0.0-SNAPSHOT")
+
+ and:
+ gitRepo.branchExists('merge-back-7.0.0-RC1')
+
+ and:
+ gitRepo.getRefProjectVersion('merge-back-7.0.0-RC1', 'foo.properties') == '7.0.0-SNAPSHOT'
+ gitRepo.getRefProjectVersion('main', 'foo.properties') == '7.0.0-SNAPSHOT'
+ gitRepo.getRefProjectVersion('v7.0.0-RC1', 'foo.properties') == '7.0.0-RC1'
+
+ cleanup:
+ System.out.println("Container logs:\n${action.actionLogs}" as String)
+ gitRepo?.close()
+ action.close()
+ }
+
def 'success - merge pr created - tag v7.0.0-RC1 to 7.0.x branch'() {
given:
Network net = Network.newNetwork()
diff --git a/tests/src/test/groovy/org/apache/grails/github/PreReleaseSpec.groovy b/tests/src/test/groovy/org/apache/grails/github/PreReleaseSpec.groovy
index 3cc89d8..7be81f2 100644
--- a/tests/src/test/groovy/org/apache/grails/github/PreReleaseSpec.groovy
+++ b/tests/src/test/groovy/org/apache/grails/github/PreReleaseSpec.groovy
@@ -74,6 +74,58 @@
action.close()
}
+ def 'success - different property file name'() {
+ given:
+ Network net = Network.newNetwork()
+
+ and:
+ GitHubVersion release = new GitHubVersion(version: '7.0.0-RC1', tagName: 'v7.0.0-RC1', targetBranch: 'main', targetVersion: '7.0.0-SNAPSHOT')
+ GitHubDockerAction action = new GitHubDockerAction('pre-release', release)
+
+ GitHubRepoMock gitRepo = new GitHubRepoMock(action.workspacePath, net)
+ gitRepo.init()
+ gitRepo.populateRepository('7.0.0-SNAPSHOT', 'v7.0.0-RC1', [], [
+ 'README.md' : '# demo\n',
+ 'foo.properties': "projectVersion=7.0.0-SNAPSHOT\n"
+ ])
+ gitRepo.stageRepositoryForAction('v7.0.0-RC1', true)
+
+ and:
+ def env = action.getDefaultEnvironment()
+ env['PROPERTY_FILE_NAME'] = 'foo.properties'
+
+ and:
+ action.createContainer(env, net)
+
+ when:
+ action.runAction()
+
+ then:
+ action.actionExitCode == 0L
+ action.actionLogs
+
+ and: 'release version'
+ action.getActionGroupLogs('Setup').contains('Release Version: 7.0.0-RC1')
+
+ and: 'next version'
+ action.getActionGroupLogs('Pushing Project Changes').contains('Pushing release version and recreating v7.0.0-RC1 tag')
+
+ and: 'target branch'
+ action.getActionGroupLogs('Updating Release for Project Changes').contains('Pre Release steps complete')
+
+ and: 'project version updated'
+ action.workspacePath.resolve('foo.properties').toFile().text.contains("projectVersion=7.0.0-RC1")
+
+ and:
+ gitRepo.getRefProjectVersion('main', 'foo.properties') == '7.0.0-SNAPSHOT'
+ gitRepo.getRefProjectVersion('v7.0.0-RC1', 'foo.properties') == '7.0.0-RC1'
+
+ cleanup:
+ System.out.println("Container logs:\n${action.actionLogs}" as String)
+ gitRepo?.close()
+ action.close()
+ }
+
def 'success - tag with custom prefix updated with version'() {
given:
Network net = Network.newNetwork()
diff --git a/tests/src/test/groovy/org/apache/grails/github/mocks/GitHubRepoMock.groovy b/tests/src/test/groovy/org/apache/grails/github/mocks/GitHubRepoMock.groovy
index 2e50000..be7ca8d 100644
--- a/tests/src/test/groovy/org/apache/grails/github/mocks/GitHubRepoMock.groovy
+++ b/tests/src/test/groovy/org/apache/grails/github/mocks/GitHubRepoMock.groovy
@@ -422,13 +422,13 @@
}
}
- String getRefProjectVersion(String refName) {
- String contents = getFileContents('gradle.properties', refName)
+ String getRefProjectVersion(String refName, String propertyFilename = 'gradle.properties') {
+ String contents = getFileContents(propertyFilename, refName)
def matcher = (contents =~ /projectVersion=(.+)/)
if (matcher) {
return matcher[0][1] as String
} else {
- throw new IllegalStateException("Could not find projectVersion in 'gradle.properties' for ref $refName" as String)
+ throw new IllegalStateException("Could not find projectVersion in '$propertyFilename' for ref $refName" as String)
}
}