-
Notifications
You must be signed in to change notification settings - Fork 28
131 lines (117 loc) · 4.65 KB
/
create-release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Create Release
on:
push:
branches: ['main']
paths: ['*/poetry.lock']
jobs:
checks:
name: "Create Release"
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
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.9'
# ----------------------------------------------
# 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
for file in ${get_changed_files}; do
if [[ $file == *"/poetry.lock"* ]] && [[ $file != *"integration/poetry.lock"* ]]; then
for plugin in ${upgraded_plugins}; do
if [[ $file == *"$plugin"* ]]; then
echo "Upgrade Detected for $plugin in file $file"
found_upgrade=true
fi
done
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