Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support working-directory & monorepo #43

Open
wants to merge 26 commits into
base: v1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/release-that.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ jobs:
major-tag: auto
github-token: ${{ secrets.GH_TOKEN }}

# test 6
- name: Test 'working-directory=.github' input
uses: ./
with:
dry-run: true
working-directory: .github
github-token: ${{ secrets.GH_TOKEN }}

release:
runs-on: ubuntu-latest
needs: os-testing
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,37 @@ Whether to make a release in `dry-run` mode. The outputs act like a release was
dry-run: true
```

### `working-directory`

Setup the working directory to generate the released version and be used in the generated tag.
Only changes inside the working directory will trigger the version generation.

> [!TIP]
> You can have as many `rlespinasse/release-that@v1` steps in your workflow if you configure `working-directory` input each time.

```yaml
- uses: rlespinasse/release-that@v1
with:
working-directory: "backend"

- uses: rlespinasse/release-that@v1
with:
working-directory: "frontend"
```

If `backend` and `frontend` folder already have a `1.0.0` release each, then

| Changes | New version tag(s) |
| ------------------------------------ | ------------------------------- |
| feat in `backend` | backend-v1.1.0 |
| fix in `frontend` | frontend-v1.0.1 |
| fix in `backend`, feat in `frontend` | backend-v1.0.1, frontend-v1.1.0 |

### `without-prefix`

> [!WARNING]
> This input behavior is not applied on the **major tag** generation when `major-tag` input is active.

Remove prefix from released version, like `v1.0.0` -> `1.0.0` (doesn't apply to major tag)

```yaml
Expand Down
53 changes: 39 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ inputs:
semantic_version:
required: true
# Read https://github.com/cycjimmy/semantic-release-action#semantic_version
default: ''
default: '24.1.0'
description: 'Specify specifying version range for semantic-release. If no version range is specified, latest version will be used by default'
working-directory:
required: true
# Read https://github.com/cycjimmy/semantic-release-action#working_directory
default: ''
description: 'Specify another working directory for semantic release. Default one is provided by github.'
dry-run:
description: 'Whether to run semantic release in `dry-run` mode'
default: 'false'
Expand Down Expand Up @@ -55,39 +60,59 @@ branding:
runs:
using: 'composite'
steps:
- uses: rlespinasse/github-slug-action@v5
# Setup steps
- name: Enhance GitHub context
uses: rlespinasse/github-slug-action@v5
with:
prefix: RT_
- name: Prepare working directory slug data
id: working-directory-slug
uses: rlespinasse/slugify-value@v1
with:
key: WORKING_DIRECTORY
value: ${{ inputs.working-directory }}
prefix: RT_
- run: $GITHUB_ACTION_PATH/setup.sh
- name: Do preflight to release that
id: preflight
run: $GITHUB_ACTION_PATH/setup.sh
shell: bash
env:
INPUT_DRYRUN: ${{ inputs.dry-run }}
INPUT_WITHOUTPREFIX: ${{ inputs.without-prefix }}
REPOSITORY_NAME: ${{ env.RT_GITHUB_REPOSITORY_NAME_PART }}
REF_POINT: ${{ env.RT_GITHUB_REF_NAME }}
SETUP_DRYRUN: ${{ inputs.dry-run }}
SETUP_WORKINGDIRECTORY: ${{ inputs.working-directory }}
SETUP_WORKINGDIRECTORYSLUG: ${{ steps.working-directory-slug.outputs.slug }}
SETUP_WITHOUTPREFIX: ${{ inputs.without-prefix }}
SETUP_REPOSITORY_NAME: ${{ env.RT_GITHUB_REPOSITORY_NAME_PART }}
SETUP_GITHUB_REF_POINT: ${{ env.RT_GITHUB_REF_NAME }}

# Main step
- name: Semantic Release
id: semantic-release
uses: cycjimmy/semantic-release-action@v4
with:
semantic_version: ${{ inputs.semantic_version }}
working_directory: ${{ inputs.working-directory }}
dry_run: ${{ inputs.dry-run }}
ci: true
extra_plugins: |
@semantic-release/commit-analyzer
@semantic-release/release-notes-generator
@semantic-release/git
@semantic-release/github
extends: |
${{ steps.preflight.outputs.extends-config }}
env:
GITHUB_TOKEN: ${{ inputs.github-token }}

# Major tag steps
- name: Major Tag Publication
id: major-tag
run: $GITHUB_ACTION_PATH/major-tag.sh
shell: bash
env:
INPUT_DRYRUN: ${{ inputs.dry-run }}
INPUT_MAJORTAG: ${{ inputs.major-tag }}
INPUT_WITHOUTPREFIX: ${{ inputs.without-prefix }}
INPUT_GITHUB_TOKEN: ${{ inputs.github-token }}
NEW_RELEASE_PUBLISHED: ${{ steps.semantic-release.outputs.new_release_published }}
NEW_RELEASE_VERSION: ${{ steps.semantic-release.outputs.new_release_version }}
NEW_RELEASE_MAJOR_VERSION: ${{ steps.semantic-release.outputs.new_release_major_version }}
MAJOR_TAG_DRYRUN: ${{ inputs.dry-run }}
MAJOR_TAG_MAJORTAG: ${{ inputs.major-tag }}
MAJOR_TAG_GITHUB_TOKEN: ${{ inputs.github-token }}
MAJOR_TAG_NEW_RELEASE_PUBLISHED: ${{ steps.semantic-release.outputs.new_release_published }}
MAJOR_TAG_NEW_RELEASE_VERSION: ${{ steps.semantic-release.outputs.new_release_version }}
MAJOR_TAG_NEW_RELEASE_GIT_TAG: ${{ steps.semantic-release.outputs.new_release_git_tag }}
MAJOR_TAG_NEW_RELEASE_MAJOR_VERSION: ${{ steps.semantic-release.outputs.new_release_major_version }}
34 changes: 14 additions & 20 deletions major-tag.sh
Original file line number Diff line number Diff line change
@@ -1,57 +1,51 @@
#!/usr/bin/env bash

if [ "${INPUT_MAJORTAG}" == "false" ]; then
if [ "${MAJOR_TAG_MAJORTAG}" == "false" ]; then
echo "Major Tag publication disabled, skipping it."
if [ -f "$GITHUB_OUTPUT" ]; then
echo "major_tag_published=false" >> "$GITHUB_OUTPUT"
echo "major_tag_published=false" >>"$GITHUB_OUTPUT"
else
echo "::set-output name=major_tag_published::false"
fi
exit 0
fi

if [ "${NEW_RELEASE_PUBLISHED}" == "false" ]; then
echo "No new release published, skipping major tag publication."
if [ "${MAJOR_TAG_NEW_RELEASE_PUBLISHED}" == "false" ]; then
echo "No MAJOR_TAG_NEW release published, skipping major tag publication."
if [ -f "$GITHUB_OUTPUT" ]; then
echo "major_tag_published=false" >> "$GITHUB_OUTPUT"
echo "major_tag_published=false" >>"$GITHUB_OUTPUT"
else
echo "::set-output name=major_tag_published::false"
fi
exit 0
fi

if [ "${INPUT_MAJORTAG}" == "auto" ]; then
if [ "${MAJOR_TAG_MAJORTAG}" == "auto" ]; then
echo "Check conditions to publish major Tag (auto mode):"
if [ -s "action.yml" ] || [ -s "action.yaml" ]; then
echo "It's a GitHub Action."
else
echo "No conditions met, skipping major tag publication."
if [ -f "$GITHUB_OUTPUT" ]; then
echo "major_tag_published=false" >> "$GITHUB_OUTPUT"
echo "major_tag_published=false" >>"$GITHUB_OUTPUT"
else
echo "::set-output name=major_tag_published::false"
fi
exit 0
fi
fi

tag_name="v${NEW_RELEASE_VERSION}"
if [ "${INPUT_WITHOUTPREFIX}" == "true" ]; then
tag_name="${NEW_RELEASE_VERSION}"
fi

echo "Publication of v${NEW_RELEASE_MAJOR_VERSION} based on ${tag_name}"
echo "Publication of v${MAJOR_TAG_NEW_RELEASE_MAJOR_VERSION} based on ${MAJOR_TAG_NEW_RELEASE_GIT_TAG}"
if [ -f "$GITHUB_OUTPUT" ]; then
echo "major_tag=v${NEW_RELEASE_MAJOR_VERSION}" >> "$GITHUB_OUTPUT"
echo "major_tag=v${MAJOR_TAG_NEW_RELEASE_MAJOR_VERSION}" >>"$GITHUB_OUTPUT"
else
echo "::set-output name=major_tag::v${NEW_RELEASE_MAJOR_VERSION}"
echo "::set-output name=major_tag::v${MAJOR_TAG_NEW_RELEASE_MAJOR_VERSION}"
fi


if [ "${INPUT_DRYRUN}" == "false" ]; then
git push origin "${tag_name}:v${NEW_RELEASE_MAJOR_VERSION}" --force || {
if [ "${MAJOR_TAG_DRYRUN}" == "false" ]; then
git push origin "${MAJOR_TAG_NEW_RELEASE_GIT_TAG}:v${MAJOR_TAG_NEW_RELEASE_MAJOR_VERSION}" --force || {
if [ -f "$GITHUB_OUTPUT" ]; then
echo "major_tag_published=false" >> "$GITHUB_OUTPUT"
echo "major_tag_published=false" >>"$GITHUB_OUTPUT"
else
echo "::set-output name=major_tag_published::false"
fi
Expand All @@ -60,7 +54,7 @@ if [ "${INPUT_DRYRUN}" == "false" ]; then
fi

if [ -f "$GITHUB_OUTPUT" ]; then
echo "major_tag_published=true" >> "$GITHUB_OUTPUT"
echo "major_tag_published=true" >>"$GITHUB_OUTPUT"
else
echo "::set-output name=major_tag_published::true"
fi
52 changes: 40 additions & 12 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,56 @@ if [ -z "$GITHUB_ACTION_PATH" ]; then
GITHUB_ACTION_PATH=.
fi

PACKAGE_CONFIG_PATH=.
PACKAGE_NAME="${SETUP_REPOSITORY_NAME}"
if [ -n "$SETUP_WORKINGDIRECTORY" ]; then
PACKAGE_CONFIG_PATH="$SETUP_WORKINGDIRECTORY"
PACKAGE_NAME="$SETUP_WORKINGDIRECTORYSLUG"
fi

TAG_FORMAT="v\${version}"
if [ -n "$SETUP_WORKINGDIRECTORY" ]; then
if [ "${SETUP_WITHOUTPREFIX}" == "true" ]; then
TAG_FORMAT="${SETUP_WORKINGDIRECTORYSLUG}-\${version}"
else
TAG_FORMAT="${SETUP_WORKINGDIRECTORYSLUG}-v\${version}"
fi
elif [ "${SETUP_WITHOUTPREFIX}" == "true" ]; then
TAG_FORMAT="\${version}"
fi

echo "Create package.json file"
echo '{"description": "","private": true,"version": "0.0.0","release":{}}' >package.json
# shellcheck disable=SC2094
cat <<<"$(jq --arg name "${REPOSITORY_NAME}" '. += {name: $name}' package.json)" >package.json
cat <<EOF >"$PACKAGE_CONFIG_PATH/package.json"
{
"name": "${PACKAGE_NAME}",
"description": "",
"private": true,
"version": "0.0.0",
"engines": {
"node": ">=20.0.0"
},
"release": {
"tagFormat": "${TAG_FORMAT}"
}
}
EOF

if [ "${INPUT_DRYRUN}" == "true" ]; then
if [ -n "${REF_POINT}" ]; then
if [ "${SETUP_DRYRUN}" == "true" ]; then
if [ -n "${SETUP_GITHUB_REF_POINT}" ]; then
echo " - Setup current branch as releasable (dry-run mode)"
# shellcheck disable=SC2094
cat <<<"$(jq --arg branch "${REF_POINT}" '.release += {branches: [$branch]}' package.json)" >package.json
cat <<<"$(jq --arg branch "${SETUP_GITHUB_REF_POINT}" '.release += {branches: [$branch]}' "$PACKAGE_CONFIG_PATH/package.json")" >"$PACKAGE_CONFIG_PATH/package.json"
else
echo " Fallback to releasable branches since not current branch is found (dry-run mode)"
cat <<<"$(jq --argjson branches "$(<"${GITHUB_ACTION_PATH}"/branches.json)" '.release += {branches: $branches}' package.json)" >package.json
cat <<<"$(jq --argjson branches "$(<"${GITHUB_ACTION_PATH}"/branches.json)" '.release += {branches: $branches}' "$PACKAGE_CONFIG_PATH/package.json")" >"$PACKAGE_CONFIG_PATH/package.json"
fi
else
echo " - Setup releasable branches"
# shellcheck disable=SC2094
cat <<<"$(jq --argjson branches "$(<"${GITHUB_ACTION_PATH}"/branches.json)" '.release += {branches: $branches}' package.json)" >package.json
cat <<<"$(jq --argjson branches "$(<"${GITHUB_ACTION_PATH}/branches.json")" '.release += {branches: $branches}' "$PACKAGE_CONFIG_PATH/package.json")" >"$PACKAGE_CONFIG_PATH/package.json"
fi

if [ "${INPUT_WITHOUTPREFIX}" == "true" ]; then
echo " - Remove prefix from released version"
# shellcheck disable=SC2094
cat <<<"$(jq '.release += {tagFormat: "${version}"}' package.json)" >package.json
if [ -n "$SETUP_WORKINGDIRECTORY" ]; then
echo "Setup monorepo support"
echo "extends-config=semantic-release-monorepo" >>"$GITHUB_OUTPUT"
fi
Loading