From efaf6150f4e31a5b508f2852efa504c61ad959a9 Mon Sep 17 00:00:00 2001 From: Olivier ORAND Date: Thu, 18 Jan 2024 09:40:39 +0000 Subject: [PATCH] feature(new-output): add tagged-version output --- .github/workflows/on-commit.yml | 52 +++++++++++++++++++++++++++++++-- README.md | 10 +++++++ action.yml | 10 +++++-- entrypoint.sh | 20 ++++++++----- 4 files changed, 81 insertions(+), 11 deletions(-) diff --git a/.github/workflows/on-commit.yml b/.github/workflows/on-commit.yml index 95dfc46..5130097 100644 --- a/.github/workflows/on-commit.yml +++ b/.github/workflows/on-commit.yml @@ -53,7 +53,14 @@ jobs: tag_name: "v0.3.0" override_existing: "true" debug: 1 - - name: Generated final files status - override + - name: Assert final files status - override + env: + OUTPUT_VERSION: "${{ steps.test_final_release.outputs.version }}" + OUTPUT_TAGGED_VERSION: "${{ steps.test_final_release.outputs.tagged_version }}" + OUTPUT_NEED_GH_RELEASE: "${{ steps.test_final_release.outputs.need_gh_release }}" + EXPECTED_OUTPUT_VERSION: "0.3.0" + EXPECTED_OUTPUT_TAGGED_VERSION: "v0.3.0" + EXPECTED_OUTPUT_NEED_GH_RELEASE: "false" run: | ls -lrt cd final-release-creation-test @@ -66,6 +73,23 @@ jobs: echo "Ensure tag exist v0.3.0" git tag --list|grep -E "^v0.3.0$" cd .. + for o in OUTPUT_VERSION OUTPUT_TAGGED_VERSION OUTPUT_NEED_GH_RELEASE;do + output=$(echo "echo \$$o") + output_value=$(eval $output) + expected=$(echo "echo \$EXPECTED_$o") + expected_value=$(eval $expected) + if [[ "$expected_value" != "$output_value" ]];then + failure="true" + echo "ERROR: $o - expected_value ($expected_value) != output_value ($output_value)" + else + echo "$o is fine ($expected_value)" + fi + done + if [ "$failure" = "true" ]; then + echo "Test failure detected" + exit 1 + fi + - name: Get Next Version id: semver-final-release run: | @@ -76,8 +100,10 @@ jobs: patch=$(echo $latest_tag|cut -d'.' -f3) next_patch=$((patch + 1)) nextVersion=${major_minor}.$next_patch + nextStrictVersion=${major_minor#v}.$next_patch echo "nextVersion: $nextVersion" echo "nextVersion=$nextVersion" >> "$GITHUB_OUTPUT" + echo "nextStrictVersion=$nextStrictVersion" >> "$GITHUB_OUTPUT" cd .. - name: Test final release creation new tag id: test_final_new_release @@ -90,9 +116,15 @@ jobs: tag_name: "${{ steps.semver-final-release.outputs.nextVersion }}" override_existing: "false" debug: 1 - - name: Generated final files status - new + - name: Assert final files status - new env: NEXT_VERSION: "${{ steps.semver-final-release.outputs.nextVersion }}" + OUTPUT_VERSION: "${{ steps.test_final_new_release.outputs.version }}" + OUTPUT_TAGGED_VERSION: "${{ steps.test_final_new_release.outputs.tagged_version }}" + OUTPUT_NEED_GH_RELEASE: "${{ steps.test_final_new_release.outputs.need_gh_release }}" + EXPECTED_OUTPUT_VERSION: "${{ steps.semver-final-release.outputs.nextStrictVersion }}" + EXPECTED_OUTPUT_TAGGED_VERSION: "${{ steps.semver-final-release.outputs.nextVersion }}" + EXPECTED_OUTPUT_NEED_GH_RELEASE: "true" run: | ls -lrt cd final-release-creation-test @@ -106,3 +138,19 @@ jobs: echo "Ensure tag exist" git tag --list|grep -E "^$NEXT_VERSION$" cd .. + for o in OUTPUT_VERSION OUTPUT_TAGGED_VERSION OUTPUT_NEED_GH_RELEASE;do + output=$(echo "echo \$$o") + output_value=$(eval $output) + expected=$(echo "echo \$EXPECTED_$o") + expected_value=$(eval $expected) + if [[ "$expected_value" != "$output_value" ]];then + failure="true" + echo "ERROR: $o - expected_value ($expected_value) != output_value ($output_value)" + else + echo "$o is fine ($expected_value)" + fi + done + if [ "$failure" = "true" ]; then + echo "Test failure detected" + exit 1 + fi \ No newline at end of file diff --git a/README.md b/README.md index ba80e93..242b276 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,13 @@ default: `.` Set to 1 to enable debug mode default: 0 + +### `force_version_consistency` +Ensure output tagged_version and version are always identical, using version as source. Otherwise, 'tagged_version' starts with 'v' prefix.Default: false. + +required: `false` +default: `false` + ## Outputs ### `file` @@ -43,6 +50,9 @@ version of the generated bosh release Do we need to create a GitHub release associated to this bosh release +### `tagged_version` + +Only set when a final release is created, otherwise it is empty. It matches 'version', but always starts with 'v'. ## Example usage ``` diff --git a/action.yml b/action.yml index c481702..3b6ba88 100644 --- a/action.yml +++ b/action.yml @@ -21,18 +21,24 @@ inputs: override_existing: description: "override existing tag or release" required: false - default: false + default: "false" dir: description: "Release directory path if not current working directory (default: .)" default: "." + force_version_consistency: + description: "Ensure output tagged_version and version are always identical, using version as source. Otherwise, 'tagged_version' starts with 'v' prefix.Default: false" + required: false + default: "false" debug: description: "Set to 1 to enable debug mode" - default: 0 + default: "0" outputs: file: description: "generated bosh release filename" version: description: "version of the generated bosh release" + tagged_version: + description: "Only set when a final release is created, otherwise it is empty. It matches 'version', but always starts with 'v'" need_gh_release: description: "Do we need to create a github release associated to this bosh release" diff --git a/entrypoint.sh b/entrypoint.sh index f4782d0..26acb3c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -18,27 +18,32 @@ elif [[ "$GITHUB_REF" == refs/pull/* ]]; then fi echo "*** Inputs ***" +echo " debug: $INPUT_DEBUG" echo " dir: $INPUT_DIR" -echo " repository: $INPUT_REPOSITORY" -echo " token: **redacted**" +echo " force_version_consistency: $INPUT_FORCE_VERSION_CONSISTENCY" echo " override_existing: $INPUT_OVERRIDE_EXISTING" +echo " repository: $INPUT_REPOSITORY" echo " tag_name: $INPUT_TAG_NAME" echo " target_branch: $INPUT_TARGET_BRANCH" -echo " debug: $INPUT_DEBUG" +echo " token: **redacted**" if [[ "$INPUT_DIR" != "." ]];then cd $INPUT_DIR # We ensure we are in the right directory git config --global --add safe.directory /github/workspace/$INPUT_DIR fi - +tagged_version="" if [ -n "$INPUT_TAG_NAME" ];then - echo "Tag_name detected. Overriding version name and enabling final release" + echo "Tag_name detected. Overriding version name and enabling final release. And enforcing 'v' prefix" version=$INPUT_TAG_NAME version=${version#v} - tag_version=v${version} + tagged_version=v${version} release=true fi +if [ "$INPUT_FORCE_VERSION_CONSISTENCY" == "true" ];then + echo "Ensure version and tagged_version are identical" + tagged_version=${version} +fi if [ "$INPUT_DEBUG" -ne 0 ];then echo "Current files before release creation:" @@ -125,7 +130,7 @@ if [ "${release}" == "true" ]; then else echo "pushing changes to git repository" # Override any existing tag with same version. This may happen if only part of the renovate PRs were merged - git tag -a -m "cutting release ${tag_version}" ${tag_version} $PUSH_OPTIONS + git tag -a -m "cutting release ${tagged_version}" ${tagged_version} $PUSH_OPTIONS # In case a renovate PR was merged in between, try to rebase prior to pushing git pull --rebase ${remote_repo} if [[ "${INPUT_OVERRIDE_EXISTING}" == "true" ]]; then @@ -149,5 +154,6 @@ chmod 644 ${name}-${version}.tgz # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files echo "file=${name}-${version}.tgz" >> $GITHUB_OUTPUT echo "version=${version}" >> $GITHUB_OUTPUT +echo "tagged_version=${tagged_version}" >> $GITHUB_OUTPUT echo "need_gh_release=${NEED_GITHUB_RELEASE}" >> $GITHUB_OUTPUT