π NATS Plugin π§ (#666) #27
This file contains 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
name: Create Release | |
on: | |
push: | |
branches: ['main'] | |
paths: ['*/poetry.lock'] | |
jobs: | |
checks: | |
name: "Create Release" | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
outputs: | |
current_global_version: ${{ steps.current_global_version.outputs.version }} | |
should_create_release: ${{ steps.should_create_release.outputs.should_create_release }} | |
body: ${{ steps.prepare_release.outputs.body }} | |
tag: ${{ steps.prepare_release.outputs.tag }} | |
defaults: | |
run: | |
working-directory: . | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# ---------------------------------------------- | |
# Install Python | |
# ---------------------------------------------- | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
#---------------------------------------------- | |
# Check the latest version from plugins_global lock file | |
#---------------------------------------------- | |
- name: Get global aries-cloudagent version from plugins repo | |
id: current_global_version | |
run: | | |
cd plugin_globals | |
lock_version=$(grep -A1 'name = "aries-cloudagent"' poetry.lock | grep -v 'name = "aries-cloudagent"') | |
version=$(grep -oP '(?<=").*?(?=")' <<< "$lock_version") | |
echo current_global_version=$version >> $GITHUB_OUTPUT | |
echo "Global version = $version" | |
# ---------------------------------------------- | |
# Check if a release should be created | |
# ---------------------------------------------- | |
- name: Check If Release Should Be Created | |
id: should_create_release | |
run: | | |
found_upgrade=false | |
get_changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }}) | |
echo "${get_changed_files}" | |
upgraded_plugins=$(python repo_manager.py 5) | |
echo "${upgraded_plugins}" | |
# Check if any of the changed files are poetry.lock files | |
# and if they not match the global poetry.lock file | |
# Compare versions | |
current_global_version="${{steps.current_global_version.outputs.current_global_version}}" | |
sem_version () { | |
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; | |
} | |
for file in ${get_changed_files}; do | |
number_of_slashes=$(grep -o "/" <<< "$file" | wc -l) | |
# Check if the lock file is rooted | |
if [[ $file == *"/poetry.lock"* ]] && [[ "$number_of_slashes" == 1 ]]; then | |
changes="$(git diff ${{ github.event.before }} ${{ github.event.after }} $file)" | |
lock_version=$(echo "$changes" | grep -A1 'name = "aries-cloudagent"' | head -n 2 | tail -n 1 | awk '{print $3}' | tr -d '"') | |
echo "File = $file" | |
echo "Old Version = $lock_version" | |
echo "Global Version = $current_global_version" | |
if [[ "$lock_version" ]] && [[ $(sem_version $current_global_version) -gt $(sem_version $lock_version) ]]; then | |
echo "Upgrade Detected in $file" | |
found_upgrade=true | |
break | |
fi | |
fi | |
done | |
if [ "$found_upgrade" = true ] | |
then | |
echo "Upgrade Detected. Creating Release" | |
else | |
echo "No Upgrade Detected. Skipping Release Creation." | |
fi | |
echo should_create_release=$found_upgrade >> $GITHUB_OUTPUT | |
# ---------------------------------------------- | |
# Prepare Release | |
# ---------------------------------------------- | |
- name: Prepare Release | |
id: prepare_release | |
if: steps.should_create_release.outputs.should_create_release == 'true' | |
run: | | |
echo "Creating release" | |
echo ${{ steps.should_create_release.outputs.should_create_release }} | |
# Get the latest version | |
remote_version=$(pip index versions aries-cloudagent) | |
version=$(grep -oP '(?<=Available versions: ).*?(?=,)' <<< "$remote_version") | |
# Set the git config | |
git config --global user.name 'Release Bot' | |
git config --global user.email 'release-bot@users.noreply.github.com' | |
git fetch --tags | |
# Determine the release tag | |
get_tags_output=$(git tag -n0 "*$version*") | |
echo "Tag output: ${get_tags_output}" | |
tags_num=0 | |
for item in ${get_tags_output}; do | |
tags_num=$((tags_num+1)) | |
done | |
release_tag="" | |
if [ $tags_num -eq 0 ] | |
then | |
release_tag=$version | |
else | |
release_tag="$version.$tags_num" | |
fi | |
# Get the release notes | |
body=$(python repo_manager.py 4) | |
body=${body/v$version/v$release_tag} | |
upgraded_plugins=($(python repo_manager.py 5)) | |
details=$(printf '#### Plugins upgraded this release: \n\t - ') | |
count=${#upgraded_plugins[*]} | |
for i in $(seq 0 "$(("$count" - 2))" ); | |
do | |
details=$(printf '%s %s \n\t - ' "$details" "${upgraded_plugins[$i]}") | |
done | |
details=$(printf '%s %s \n' "$details" "${upgraded_plugins[$count - 1]}") | |
# Set the outputs | |
echo tag=$release_tag >> $GITHUB_OUTPUT | |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | |
echo "release_body<<$EOF" >> $GITHUB_OUTPUT | |
echo "$body $details" >> $GITHUB_OUTPUT | |
echo "$EOF" >> $GITHUB_OUTPUT | |
# ---------------------------------------------- | |
# Create Release | |
# ---------------------------------------------- | |
- name: Create Release | |
if: steps.should_create_release.outputs.should_create_release == 'true' | |
uses: softprops/action-gh-release@v2 | |
with: | |
token: ${{ secrets.BOT_PR_PAT }} | |
name: ${{ steps.prepare_release.outputs.tag }} | |
body: ${{ steps.prepare_release.outputs.release_body }} | |
tag_name: ${{ steps.prepare_release.outputs.tag }} | |
prerelease: false | |