Skip to content

Commit

Permalink
Manage inner releases (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoanm authored Aug 25, 2024
1 parent 2c8440d commit 1631580
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions .github/yamllint-config.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`)
Expand Down
51 changes: 50 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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

0 comments on commit 1631580

Please sign in to comment.