diff --git a/.github/workflows/release-that.yaml b/.github/workflows/release-that.yaml index 1f451d0..ce358c6 100644 --- a/.github/workflows/release-that.yaml +++ b/.github/workflows/release-that.yaml @@ -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 diff --git a/README.md b/README.md index 84eb2b2..470054f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 28fb7e5..0c554e4 100644 --- a/action.yml +++ b/action.yml @@ -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' @@ -55,21 +60,37 @@ 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: | @@ -77,17 +98,21 @@ runs: @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 }} diff --git a/major-tag.sh b/major-tag.sh index 7818cc3..2b1400d 100755 --- a/major-tag.sh +++ b/major-tag.sh @@ -1,33 +1,33 @@ #!/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 @@ -35,23 +35,17 @@ if [ "${INPUT_MAJORTAG}" == "auto" ]; then 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 @@ -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 diff --git a/setup.sh b/setup.sh index 062f8b5..c3b675a 100755 --- a/setup.sh +++ b/setup.sh @@ -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 <"$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