Skip to content

Commit

Permalink
feature(new-output): add tagged-version output
Browse files Browse the repository at this point in the history
  • Loading branch information
o-orand committed Jan 18, 2024
1 parent ab7a6ff commit efaf615
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 11 deletions.
52 changes: 50 additions & 2 deletions .github/workflows/on-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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

```
Expand Down
10 changes: 8 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
20 changes: 13 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit efaf615

Please sign in to comment.