From 1631580e8b1a46e3bc592676ca640c7ccdc35096 Mon Sep 17 00:00:00 2001 From: yoanm <4410697+yoanm@users.noreply.github.com> Date: Sun, 25 Aug 2024 12:49:13 +0200 Subject: [PATCH] Manage inner releases (#5) --- .github/workflows/CI.yml | 2 +- .github/yamllint-config.yml | 13 ++++++++++ README.md | 34 +++++++++++++++++++++++-- action.yml | 51 ++++++++++++++++++++++++++++++++++++- 4 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 .github/yamllint-config.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ecacf0c..a4b5278 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -23,4 +23,4 @@ jobs: uses: actions/checkout@v4 - name: Validate action file syntax - run: yamllint -d relaxed action.yml + run: yamllint -c .github/yamllint-config.yml action.yml diff --git a/.github/yamllint-config.yml b/.github/yamllint-config.yml new file mode 100644 index 0000000..3dfbf83 --- /dev/null +++ b/.github/yamllint-config.yml @@ -0,0 +1,13 @@ +--- + +extends: default + +rules: + line-length: + max: 120 + level: warning + comments: + require-starting-space: true + ignore-shebangs: true + min-spaces-from-content: 1 + document-start: disable diff --git a/README.md b/README.md index 29d7c00..318bd97 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,9 @@ jobs: tag: name: Publish vX and vX.Y tags runs-on: ubuntu-latest + if: ${{ github.event.release.prerelease == false && github.event.release.draft == false }} permissions: - contents: write # Required to push new tags ! + contents: write # Required to manage tags & releases ! steps: - name: Checkout uses: actions/checkout@v4 @@ -44,15 +45,44 @@ jobs: > [!TIP] > The repository uses the action too, therefore a `vX` and a `vX.Y` tag are automatically created for each release ! +### `vX` / `vX.Y` on GitHub Marketplace +If you want to make `vX` and/or `vX.Y` versions available on the marketplace, follow this procedure: + +- Use `update-inner-releases` at `true` when using the action + + ```yaml + - name: Generate vX and vX.Y tags + uses: yoanm/gha-versioning@v1 + with: + update-inner-releases: true + ``` + +- Wait for the related tag (`vX` or `vX.Y`) to be created by this action. +- Manually create the releases targeting the tag (`vX` or `vX.Y` or both, up to you) and published it to the marketplace. + +Then continue creating `vX.Y.Z` releases as usual, related existing `vX` and `vX.Y` releases will be automatically updated to reflect the actual `vX.Y.Z` version. + ## Inputs - `tag`: Default to `${{ github.event.release.tag_name }}` + + The full tag used to generate vX and vX.Y tags + +- `update-inner-releases`: Default to `false`. + + Whether to also update releases name linked to `vX` and `vX.Y` tags and set them as latest if provided tag release is currently the latest release. + + > [!IMPORTANT] + > Will work only on pre-existing releases ! + - `git-email`: Default to `github-actions[bot]@users.noreply.github.com`. _Git user email is required when creating tag with a message._ - `git-name`: Default to `github-actions[bot]`. _Git user name is required when creating tag with a message._ -- `working-directory`: Directory to the Git repository to tag. Default to `${{ github.workspace }}`. +- `working-directory`: Default to `${{ github.workspace }}`. + + Directory to the Git repository to tag. ## Outputs - `minor-tag`: Minor tag created (e.g. `vX.Y`) diff --git a/action.yml b/action.yml index 263b9bb..f14fe92 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,13 @@ inputs: description: The full tag used to generate vX and vX.Y tags required: false default: ${{ github.event.release.tag_name }} + update-inner-releases: + description: | + Whether to also update releases name linked to `vX` and `vX.Y` tags and set them as latest if provided tag + release is currently the latest release. + Will work only on pre-existing releases ! + required: false + default: 'false' git-email: description: The email for the GIT user creating the tags required: false @@ -39,17 +46,28 @@ runs: steps: # Even if an input is marked as "required", empty/no value may be passed ! - shell: bash + id: validate env: FULL_TAG: ${{ inputs.tag }} working-directory: ${{ inputs.working-directory }} run: | # Validate provided tag ... - if ! [[ "$FULL_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + + if [[ "$FULL_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "tag-type=full" >> "$GITHUB_OUTPUT" + elif [[ "$FULL_TAG" =~ ^v[0-9]+\.[0-9]+$ ]]; then + echo "::notice::Minor tag detected, skipping process" + echo "tag-type=minor" >> "$GITHUB_OUTPUT" + elif [[ "$FULL_TAG" =~ ^v[0-9]+$ ]]; then + echo "::notice::Major tag detected, skipping process" + echo "tag-type=major" >> "$GITHUB_OUTPUT" + else echo "::error::Invalid tag format (expected vX.Y.Z) !" exit 1 fi; - id: generate-tags + if: ${{ steps.validate.outputs.tag-type == 'full' }} shell: bash env: FULL_TAG: ${{ inputs.tag }} @@ -75,6 +93,7 @@ runs: echo "major=$MAJOR_TAG" >> "$GITHUB_OUTPUT" - shell: bash + if: ${{ steps.validate.outputs.tag-type == 'full' }} env: FULL_TAG: ${{ inputs.tag }} MINOR_TAG: ${{ steps.generate-tags.outputs.minor }} @@ -98,3 +117,33 @@ runs: git tag -f $MINOR_TAG -m "Linked to $FULL_TAG tag" ${FULL_TAG}^{} && \ sleep 1 && git tag -f $FULL_TAG -F ./TAG_MSG ${FULL_TAG}^{} && \ git push origin --force $MINOR_TAG $MAJOR_TAG $FULL_TAG) || exit 3 + + - shell: bash + if: ${{ steps.validate.outputs.tag-type == 'full' && inputs.update-inner-releases == 'true' }} + env: + GITHUB_TOKEN: ${{ github.token }} + FULL_TAG: ${{ inputs.tag }} + MINOR_TAG: ${{ steps.generate-tags.outputs.minor }} + MAJOR_TAG: ${{ steps.generate-tags.outputs.major }} + working-directory: ${{ inputs.working-directory }} + run: | + # Update inner releases + MINOR_RELEASE_EXISTS="$(gh release view ${MINOR_TAG} --json id -q .id | wc -l )" + MAJOR_RELEASE_EXISTS="$(gh release view ${MAJOR_TAG} --json id -q .id | wc -l )" + if [[ "${MINOR_RELEASE_EXISTS}${MAJOR_RELEASE_EXISTS}" = '00' ]]; then + echo "::warning::No inner release to update !" + exit 0 + fi + AS_LATEST_PARAM="" + if [[ "`gh repo view --json latestRelease -q .latestRelease.tagName`" = "${FULL_TAG}" ]]; then + AS_LATEST_PARAM='--latest' + fi + if ! [[ "${MINOR_RELEASE_EXISTS}" = '0' ]]; then + echo "Updating minor release ${MINOR_TAG} with --title "${FULL_TAG}" ${AS_LATEST_PARAM}" + gh release edit ${MINOR_TAG} --title "${FULL_TAG}" ${AS_LATEST_PARAM} + fi + # Update major release at the end, so it will become the latest if --latest is used ! + if ! [[ "${MAJOR_RELEASE_EXISTS}" = '0' ]]; then + echo "Updating major release ${MAJOR_TAG} with --title "${FULL_TAG}" ${AS_LATEST_PARAM}" + gh release edit ${MAJOR_TAG} --title "${FULL_TAG}" ${AS_LATEST_PARAM} + fi