Skip to content

Instantly share code, notes, and snippets.

@airtonix
Last active June 11, 2025 03:05
Show Gist options
  • Save airtonix/3e7d7207736881506acb1acd3ec03cf0 to your computer and use it in GitHub Desktop.
Save airtonix/3e7d7207736881506acb1acd3ec03cf0 to your computer and use it in GitHub Desktop.
#!/bin/bash
# read the JSON input from stdin
inputs=$(cat);
# pick the paths_released from the JSON input and turn it into a bash array
paths_array=$(jq -r '.paths_released | fromjson | .[]' <<< "$inputs")
for release in $paths_array; do
echo "Creating release branch for $release"
data=$(
echo "$inputs" |
jq -r \
--arg release "$release" \
'to_entries
| map(
select( .key | startswith($release) )
| .key |= sub($release + "--"; "")
)
| from_entries'
)
tag_name=$(echo "$data" | jq -r '.tag_name')
branch_name="release/$tag_name"
echo "$branch_name"
git branch "$branch_name" "$tag_name"
git push origin "$branch_name"
done
#!/bin/bash
manifest="$1"
if [[ -z "$manifest" ]]; then
echo "Usage: $0 <path_to_manifest_file>"
exit 1
fi
# extract the versions from the manifest file
versions=$(
jq -r '
to_entries
| .[]
| .key |= split("/")
| .key |= .[-1]
| "\(.key)@v\(.value)"
' \
"$manifest"
)
conflicts=()
# check if the tags exist
for version in $versions; do
if git tag | grep -q "$version"; then
conflicts+=("$version")
fi
done
echo "${conflicts[@]}"
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/refs/heads/main/schemas/config.json",
"versioning": "always-bump-patch",
"include-component-in-tag": true,
"include-v-in-tag": true,
"tag-separator": "@",
"separate-pull-requests": true,
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"release-type": "node",
"packages": {
"apps/one": {},
"apps/two": {},
"pkgs/ui": {}
}
}
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/refs/heads/main/schemas/config.json",
"versioning": "always-bump-minor",
"include-component-in-tag": true,
"include-v-in-tag": true,
"tag-separator": "@",
"separate-pull-requests": true,
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"always-update": true,
"always-link-local": true,
"initial-version": "0.0.1",
"release-type": "node",
"packages": {
"apps/one": {},
"apps/two": {},
"pkgs/ui": {}
}
}
name: Pr
on:
pull_request:
branches:
- main
- release/*
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
permissions:
actions: read
contents: write
issues: write
deployments: write
pull-requests: write
id-token: write
jobs:
ReleaseConflictCheck:
runs-on: ubuntu-latest
steps:
# is this a release please PR? test the labels
# release please creates labels for release prs like `pending-autorelease`
# if this isn't a release please PR, we don't need to do anything
- run: |
if [[ ! $(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name' | grep 'pending-autorelease') ]]; then
echo "This is not a release please PR, skipping release conflict check"
exit 0
fi
# release please updates the release-please-manifest.json file with it's proposed versions
# find that and check if the version is already in use
# the file lookws like :
# {
# "apps/one": "0.1.0",
# "apps/two": "0.1.0",
# }
#
# the tags we're looking for look like this:
# - [email protected]
# - [email protected]
#
# so we can use the jq command to extract the values and then check if the tag exists
# format the output of jq to be the tag we're looking for
- name: Check for release conflicts
run: |
conflicts="$(
.github/scripts/find-release-conflicts.sh \
.github/release-please-manifest.json
)"
if [ ${#conflicts[@]} -ne 0 ]; then
echo "Release conflicts found: ${conflicts[*]}"
echo "conflicts=${conflicts[*]}" >> $GITHUB_OUTPUT
exit 1
fi
echo "conflicts=[]" >> $GITHUB_OUTPUT
echo "No release conflicts found, proceeding with PR"
name: Release
on:
push:
branches:
# for prod releases
- main
# for hotfixes
- release/*
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
permissions:
actions: read
contents: write
issues: write
deployments: write
pull-requests: write
id-token: write
jobs:
Process:
runs-on: ubuntu-latest
env:
RELEASE_BOT_NAME: "Release Bot"
RELEASE_BOT_EMAIL: "[email protected]"
outputs:
releases_created: ${{ steps.release-please.outputs.releases_created }}
prs_created: ${{ steps.release-please.outputs.prs_created }}
prs: ${{ steps.release-please.outputs.prs }}
pr: ${{ steps.release-please.outputs.pr }}
sha: ${{ steps.release-please.outputs.sha }}
steps:
- id: config_filename
env:
DEFAULT_RELEASE_CONFIG_FILE: release-please-config.json
HOTFIX_RELEASE_CONFIG_FILE: release-please-config.hotfix.json
run: |
case "${{ github.ref_name }}" in
release/*)
echo "config_filename=${HOTFIX_RELEASE_CONFIG_FILE}" >> $GITHUB_OUTPUT
;;
*)
echo "config_filename=${DEFAULT_RELEASE_CONFIG_FILE}" >> $GITHUB_OUTPUT
;;
esac
- uses: googleapis/release-please-action@v4
id: release-please
with:
token: "${{ secrets.RELEASE_PLEASE_TOKEN }}"
config-file: ".github/${{ steps.config_filename.outputs.config_filename }}"
manifest-file: ".github/release-please-manifest.json"
target-branch: "${{ github.ref_name }}"
- name: Print Release Data
run: |
echo 'Release Data:'
echo '''
${{ toJSON(steps.release-please.outputs) }}
'''
- name: Checkout Code
if: ${{ steps.release-please.outputs.releases_created != 'false' }}
uses: actions/checkout@v4
with:
fetch-depth: 10
fetch-tags: true
ref: ${{ github.ref_name }}
persist-credentials: true
- name: Create Release Snapshot Branches
if: ${{ steps.release-please.outputs.releases_created != 'false' }}
run: |
git config --global user.name "$RELEASE_BOT_NAME"
git config --global user.email "$RELEASE_BOT_EMAIL"
echo "$(jq -cr <<< '${{ toJSON(steps.release-please.outputs) }}')" |
.github/scripts/create-release-branch.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment