Skip to content

Commit 3466225

Browse files
authored
[ci] Fix publish release (#277)
Followup on #272
1 parent c852fd6 commit 3466225

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed

.ci/files/prepare_release_notes.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -e -o pipefail
3+
4+
outfile="release_notes_prepared.md"
5+
infile="ReleaseNotes.md"
6+
7+
if [ ! -e "$infile" ]; then
8+
echo "File ${infile} not found!"
9+
exit 1
10+
fi
11+
12+
13+
# Extract the release notes.
14+
# Note: "|| test $? -eq 141" is added to ignore SIGPIPE errors when head finishes before grep is done.
15+
BEGIN_LINE=$( (grep -n "^## " "${infile}" || test $? -eq 141) | head -1|cut -d ":" -f 1)
16+
END_LINE=$( (grep -n "^## " "${infile}" || test $? -eq 141) | head -2|tail -1|cut -d ":" -f 1)
17+
END_LINE=$((END_LINE - 1))
18+
EXTRACT=$(head -$END_LINE "${infile}" | tail -$((END_LINE - BEGIN_LINE)))
19+
20+
RELEASE_BODY="A new PMD for Eclipse plugin version has been released.
21+
It is available via the update site: https://pmd.github.io/pmd-eclipse-plugin-p2-site/
22+
23+
$EXTRACT
24+
"
25+
echo "${RELEASE_BODY}" > "${outfile}"
26+
echo "Created file ${outfile}"

.ci/files/regenerate_metadata.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#!/bin/bash
22

33
echo "Regenerating metadata for p2-site..."
4-
local releases=($(find . -maxdepth 1 -type d -regex "\./[0-9]+\.[0-9]+\.[0-9]+\..*" -printf '%f\n'| tr '.' '\0' | sort -t '\0' -k1,1nr -k2,2nr -k3,3nr -k4dr |awk -F '\0' '{printf "%s.%s.%s.%s\n", $1, $2, $3, $4}'))
4+
mapfile -t releases < <(find . -maxdepth 1 -type d -regex "\./[0-9]+\.[0-9]+\.[0-9]+\..*" -printf '%f\n'| tr '.' '\0' | sort -t '\0' -k1,1nr -k2,2nr -k3,3nr -k4dr |awk -F '\0' '{printf "%s.%s.%s.%s\n", $1, $2, $3, $4}')
55
# remove old releases
66
for i in "${releases[@]:5}"; do
7-
pmd_ci_log_info "Removing old release $i..."
7+
echo " Removing old release $i..."
88
rm -rf "$i"
99
done
1010
releases=("${releases[@]:0:5}")
1111

1212
# regenerate metadata
13-
local now
1413
now=$(date +%s000)
15-
local children=""
16-
local children_index=""
14+
children=""
15+
children_index=""
1716
for i in "${releases[@]}"; do
17+
echo " Adding release $i"
1818
children="${children} <child location=\"$i\"/>\n"
1919
children_index="${children_index} * [$i]($i/)\n"
2020
echo "This is a Eclipse Update Site for the [PMD Eclipse Plugin](https://github.com/pmd/pmd-eclipse-plugin/) ${i}.
@@ -33,8 +33,8 @@ Use <https://pmd.github.io/pmd-eclipse-plugin-p2-site/${i}/> to install the plug
3333
git add "$i"/index.md
3434
done
3535

36-
local site_name="PMD for Eclipse - Update Site"
37-
local artifactsTemplate="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
36+
site_name="PMD for Eclipse - Update Site"
37+
artifactsTemplate="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
3838
<?compositeArtifactRepository version=\"1.0.0\"?>
3939
<repository name=\"${site_name}\" type=\"org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository\" version=\"1.0.0\">
4040
<properties size=\"2\">
@@ -45,8 +45,9 @@ local artifactsTemplate="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
4545
${children} </children>
4646
</repository>"
4747
echo -e "${artifactsTemplate}" > compositeArtifacts.xml
48+
git add compositeArtifacts.xml
4849

49-
local contentTemplate="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
50+
contentTemplate="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
5051
<?compositeMetadataRepository version=\"1.0.0\"?>
5152
<repository name=\"${site_name}\" type=\"org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository\" version=\"1.0.0\">
5253
<properties size=\"2\">
@@ -57,12 +58,14 @@ local contentTemplate="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
5758
${children} </children>
5859
</repository>"
5960
echo -e "${contentTemplate}" > compositeContent.xml
61+
git add compositeContent.xml
6062

6163
# p2.index
62-
local p2_index="version = 1
64+
p2_index="version = 1
6365
metadata.repository.factory.order = compositeContent.xml,\!
6466
artifact.repository.factory.order = compositeArtifacts.xml,\!"
6567
echo -e "${p2_index}" > p2.index
68+
git add p2.index
6669

6770
# regenerate index.md
6871
echo -e "This is a composite Eclipse Update Site for the [PMD Eclipse Plugin](https://github.com/pmd/pmd-eclipse-plugin/).
@@ -78,4 +81,7 @@ ${children_index}
7881
For older versions, see <https://sourceforge.net/projects/pmd/files/pmd-eclipse/zipped/>
7982
8083
" > index.md
84+
git add index.md
85+
86+
echo "Done."
8187

.github/workflows/publish-release.yml

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,7 @@ jobs:
144144
with:
145145
name: update-site
146146
- name: Prepare Release Notes
147-
run: |
148-
# extract the release notes
149-
BEGIN_LINE=$(grep -n "^## " ReleaseNotes.md|head -1|cut -d ":" -f 1)
150-
END_LINE=$(grep -n "^## " ReleaseNotes.md|head -2|tail -1|cut -d ":" -f 1)
151-
END_LINE=$((END_LINE - 1))
152-
153-
RELEASE_BODY="A new PMD for Eclipse plugin version has been released.
154-
It is available via the update site: https://pmd.github.io/pmd-eclipse-plugin-p2-site/
155-
156-
$(head -$END_LINE ReleaseNotes.md | tail -$((END_LINE - BEGIN_LINE)))
157-
"
158-
echo "${RELEASE_BODY}" > release_notes_prepared.md
147+
run: .ci/files/prepare_release_notes.sh
159148
- name: Create Release
160149
env:
161150
# Token required for GH CLI:
@@ -208,7 +197,7 @@ jobs:
208197
uploadUrl="${PMD_SF_USER}@web.sourceforge.net:/home/frs/project/pmd/pmd-eclipse/zipped/"
209198
rsync -avh \
210199
"net.sourceforge.pmd.eclipse.p2updatesite-${VERSION}.zip" \
211-
"${uploadUrl}/net.sourceforge.pmd.eclipse.p2updatesite-SNAPSHOT.zip"
200+
"${uploadUrl}/net.sourceforge.pmd.eclipse.p2updatesite-${VERSION}.zip"
212201
213202
- name: Cleanup ssh
214203
if: ${{ always() }}
@@ -226,6 +215,9 @@ jobs:
226215
run:
227216
shell: bash
228217
steps:
218+
- uses: actions/checkout@v4
219+
with:
220+
ref: ${{ github.event.workflow_run.head_branch }}
229221
- uses: actions/download-artifact@v4
230222
with:
231223
name: update-site
@@ -278,18 +270,7 @@ jobs:
278270
with:
279271
ref: ${{ github.event.workflow_run.head_branch }}
280272
- name: Prepare Release Notes
281-
run: |
282-
# extract the release notes
283-
BEGIN_LINE=$(grep -n "^## " ReleaseNotes.md|head -1|cut -d ":" -f 1)
284-
END_LINE=$(grep -n "^## " ReleaseNotes.md|head -2|tail -1|cut -d ":" -f 1)
285-
END_LINE=$((END_LINE - 1))
286-
287-
RELEASE_BODY="A new PMD for Eclipse plugin version has been released.
288-
It is available via the update site: https://pmd.github.io/pmd-eclipse-plugin-p2-site/
289-
290-
$(head -$END_LINE ReleaseNotes.md | tail -$((END_LINE - BEGIN_LINE)))
291-
"
292-
echo "${RELEASE_BODY}" > release_notes_prepared.md
273+
run: .ci/files/prepare_release_notes.sh
293274
- name: Create Blog Post
294275
id: upload
295276
env:

0 commit comments

Comments
 (0)