Repository navigation
[DX-3325] Release automático del SDK al mergear PRs con label release:* #138
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
Merged
pibahamondesw
merged 3 commits into
master
from
dx-3325-release-automatico-de-fintoc-python-al-mergear-prs-con-label
Nov 6, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #!/usr/bin/env bash | ||
| # Decide the bump and release notes for the release workflow. | ||
| # Writes `bump` (empty means skip the release) and `notes` to $GITHUB_OUTPUT. | ||
| # | ||
| # Required env: EVENT_NAME, GITHUB_OUTPUT | ||
| # workflow_dispatch: INPUT_BUMP, INPUT_NOTES | ||
| # push: SHA, PULLS_JSON (response of GET repos/{repo}/commits/{sha}/pulls) | ||
| set -euo pipefail | ||
|
|
||
| extract_release_notes() { | ||
| perl -0777 -ne ' | ||
| s/\r//g; | ||
| s/<!--.*?-->//gs; | ||
| if (/^##[ \t]+Release notes[ \t]*$(.*?)(?=^##[ \t]|\z)/msi) { | ||
| my $notes = $1; | ||
| $notes =~ s/^\s+|\s+$//g; | ||
| print $notes; | ||
| } | ||
| ' | ||
| } | ||
|
|
||
| trim() { | ||
| perl -0777 -pe 's/^\s+|\s+$//g' | ||
| } | ||
|
|
||
| write_output() { | ||
| local bump=$1 notes=$2 delimiter | ||
| delimiter="RELEASE_NOTES_$(openssl rand -hex 16)" | ||
| { | ||
| echo "bump=$bump" | ||
| echo "notes<<$delimiter" | ||
| printf '%s\n' "$notes" | ||
| echo "$delimiter" | ||
| } >> "$GITHUB_OUTPUT" | ||
| } | ||
|
|
||
| skip_release() { | ||
| echo "::notice::$1 Skipping release." | ||
| write_output "" "" | ||
| } | ||
|
|
||
| resolve_from_dispatch() { | ||
| write_output "$INPUT_BUMP" "$(printf '%s' "${INPUT_NOTES:-}" | trim)" | ||
| } | ||
|
|
||
| resolve_from_push() { | ||
| local pr number labels label_count bump | ||
| pr=$(jq -c --arg sha "$SHA" \ | ||
| 'map(select(.merged_at != null and .merge_commit_sha == $sha)) | first // empty' \ | ||
| <<< "$PULLS_JSON") | ||
| if [ -z "$pr" ]; then | ||
| skip_release "No merged PR found for $SHA." | ||
| return | ||
| fi | ||
|
|
||
| number=$(jq -r '.number' <<< "$pr") | ||
| labels=$(jq -r '[.labels[].name | select(startswith("release:"))] | join(" ")' <<< "$pr") | ||
| label_count=$(jq '[.labels[].name | select(startswith("release:"))] | length' <<< "$pr") | ||
|
|
||
| if [ "$label_count" -eq 0 ]; then | ||
| skip_release "PR #$number has no release:* label." | ||
| return | ||
| fi | ||
| if [ "$label_count" -gt 1 ]; then | ||
| echo "::error::PR #$number has more than one release:* label ($labels). Keep only one." | ||
| exit 1 | ||
| fi | ||
|
|
||
| bump=${labels#release:} | ||
| case "$bump" in | ||
| patch|minor|major) ;; | ||
| *) | ||
| echo "::error::PR #$number has an unknown label $labels. Use release:patch, release:minor or release:major." | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| echo "Releasing PR #$number with bump $bump." | ||
| write_output "$bump" "$(jq -r '.body // ""' <<< "$pr" | extract_release_notes)" | ||
| } | ||
|
|
||
| case "$EVENT_NAME" in | ||
| workflow_dispatch) resolve_from_dispatch ;; | ||
| push) resolve_from_push ;; | ||
| *) | ||
| echo "::error::Unsupported event $EVENT_NAME." | ||
| exit 1 | ||
| ;; | ||
| esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #!/usr/bin/env bash | ||
| set -uo pipefail | ||
|
|
||
| SCRIPT="$(dirname "$0")/resolve-release.sh" | ||
| SHA=abc123 | ||
| failures=0 | ||
|
|
||
| pulls_json() { | ||
| local labels=$1 body=$2 | ||
| jq -nc --arg sha "$SHA" --arg body "$body" --argjson labels "$labels" \ | ||
| '[{number: 7, merged_at: "2026-01-01T00:00:00Z", merge_commit_sha: $sha, | ||
| body: $body, labels: ($labels | map({name: .}))}]' | ||
| } | ||
|
|
||
| read_output() { | ||
| local file=$1 name=$2 | ||
| awk -v name="$name" ' | ||
| index($0, name "=") == 1 { print substr($0, length(name) + 2); exit } | ||
| index($0, name "<<") == 1 { delimiter = substr($0, length(name) + 3); reading = 1; next } | ||
| reading && $0 == delimiter { exit } | ||
| reading { print } | ||
| ' "$file" | ||
| } | ||
|
|
||
| assert_release() { | ||
| local description=$1 expected_status=$2 expected_bump=$3 expected_notes=$4 | ||
| shift 4 | ||
| local output status | ||
| output=$(mktemp) | ||
| env GITHUB_OUTPUT="$output" "$@" bash "$SCRIPT" > /dev/null | ||
| status=$? | ||
|
|
||
| if [ "$status" -ne "$expected_status" ]; then | ||
| echo "FAIL: $description (exit $status, expected $expected_status)" | ||
| failures=$((failures + 1)) | ||
| elif [ "$expected_status" -eq 0 ] && | ||
| { [ "$(read_output "$output" bump)" != "$expected_bump" ] || | ||
| [ "$(read_output "$output" notes)" != "$expected_notes" ]; }; then | ||
| echo "FAIL: $description" | ||
| echo " bump: '$(read_output "$output" bump)' expected '$expected_bump'" | ||
| echo " notes: '$(read_output "$output" notes)' expected '$expected_notes'" | ||
| failures=$((failures + 1)) | ||
| else | ||
| echo "ok: $description" | ||
| fi | ||
| rm -f "$output" | ||
| } | ||
|
|
||
| assert_push() { | ||
| local description=$1 expected_status=$2 expected_bump=$3 expected_notes=$4 labels=$5 body=$6 | ||
| assert_release "$description" "$expected_status" "$expected_bump" "$expected_notes" \ | ||
| EVENT_NAME=push SHA="$SHA" PULLS_JSON="$(pulls_json "$labels" "$body")" | ||
| } | ||
|
|
||
| assert_push "notes section at the end, comments stripped" 0 minor $'- Added X.\n- Removed Y.' \ | ||
| '["bug", "release:minor"]' \ | ||
| $'## Contexto\nctx\n\n## Release notes\n\n<!-- instructions\nspanning lines -->\n\n- Added X.\n- Removed Y.\n' | ||
|
|
||
| assert_push "notes section followed by another section" 0 patch $'Fixed X.\n### Details\nmore' \ | ||
| '["release:patch"]' \ | ||
| $'## Release notes\r\n\r\nFixed X.\r\n### Details\r\nmore\r\n\r\n## Rollback\r\nsafe\r\n' | ||
|
|
||
| assert_push "notes section with only a comment" 0 major "" \ | ||
| '["release:major"]' $'## Release notes\n<!-- empty -->\n## Rollback\nx' | ||
|
|
||
| assert_push "no notes section" 0 patch "" '["release:patch"]' $'## Contexto\nctx' | ||
|
|
||
| assert_push "PR without release label is skipped" 0 "" "" '["bug"]' $'## Release notes\nx' | ||
|
|
||
| assert_push "more than one release label fails" 1 "" "" '["release:patch", "release:minor"]' "x" | ||
|
|
||
| assert_push "unknown release label fails" 1 "" "" '["release:hotfix"]' "x" | ||
|
|
||
| assert_release "push without merged PR is skipped" 0 "" "" \ | ||
| EVENT_NAME=push SHA="$SHA" PULLS_JSON='[{"number": 8, "merged_at": null, "merge_commit_sha": "abc123", "labels": [{"name": "release:patch"}], "body": ""}]' | ||
|
|
||
| assert_release "workflow_dispatch uses the inputs" 0 minor "notes here" \ | ||
| EVENT_NAME=workflow_dispatch INPUT_BUMP=minor INPUT_NOTES=$' \n notes here\n' | ||
|
|
||
| assert_release "workflow_dispatch with empty notes" 0 patch "" \ | ||
| EVENT_NAME=workflow_dispatch INPUT_BUMP=patch INPUT_NOTES="" | ||
|
|
||
| [ "$failures" -eq 0 ] || { echo "$failures failing case(s)"; exit 1; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.