-
Notifications
You must be signed in to change notification settings - Fork 27
156 lines (141 loc) · 6.1 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Create Release
on:
push:
branches: ['main']
paths: ['*/poetry.lock']
jobs:
checks:
name: "Create Release"
permissions:
contents: write
runs-on: ubuntu-latest
if: github.repository == 'openwallet-foundation/acapy-plugins'
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 acapy-agent version from plugins repo
id: current_global_version
run: |
cd plugin_globals
lock_version=$(grep -A1 'name = "acapy-agent"' poetry.lock | grep -v 'name = "acapy-agent"')
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 = "acapy-agent"' | 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 acapy-agent)
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 For ACA-Py Release %s \n - ' '$version')
count=${#upgraded_plugins[*]}
for i in $(seq 0 "$(("$count" - 2))" );
do
details=$(printf '%s %s \n - ' "$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