Skip to content

Commit dca2f43

Browse files
feat: publish p2 update site to GitHub Pages via gh-pages branch
- Create a snapshot workflow that build and deploys on every push to master or v[0-9]* branches into p2/snapshots/<sha8>/; keep last 20, clean up older ones - Create a release workflow to promote existing snapshots to releases; The workflow creates a tag and copy the corresponding snapshot for that commit into p2/releases/<version>/ on gh-pages - Add composite p2 repositories (compositeContent.xml, compositeArtifacts.xml, p2.index) for p2/releases/latest/ and p2/snapshots/latest/ so Eclipse can resolve "latest" without a fixed URL - Add generated index.html listing all snapshot and release links - Document p2 update site URLs in README.md Co-authored-by: João Dinis Ferreira <Joao.Ferreira@avaloq.com>
1 parent 226f3e9 commit dca2f43

6 files changed

Lines changed: 486 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# Removes old p2 snapshots from gh-pages, keeping the last 20.
3+
# Required env vars: GITHUB_TOKEN
4+
5+
set -euo pipefail
6+
7+
cd gh-pages
8+
git config user.email "github-actions[bot]@users.noreply.github.com"
9+
git config user.name "github-actions[bot]"
10+
11+
if [ -d p2/snapshots ]; then
12+
(cd p2/snapshots && ls -1t | grep -v latest | tail -n +21 | xargs -r -I{} rm -rf "{}")
13+
fi
14+
15+
git add -A
16+
if git diff --cached --quiet; then
17+
echo "No snapshot cleanup needed"
18+
exit 0
19+
fi
20+
git commit -m "Clean up old p2 snapshots"
21+
for attempt in 1 2 3; do
22+
if git push origin HEAD:gh-pages; then
23+
exit 0
24+
fi
25+
echo "Push attempt $attempt failed; fetching and rebasing"
26+
git fetch origin gh-pages
27+
git rebase origin/gh-pages
28+
done
29+
echo "Failed to push gh-pages after 3 attempts"
30+
exit 1
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env bash
2+
# Publishes the p2 update site to the gh-pages branch.
3+
#
4+
# Snapshot mode (RELEASE_VERSION unset):
5+
# Copies ddk-repository/target/repository/ → p2/snapshots/<sha8>/
6+
# Updates p2/snapshots/latest/ composite repository
7+
#
8+
# Release mode (RELEASE_VERSION set):
9+
# Copies p2/snapshots/<SNAPSHOT_SHA>/ → p2/releases/<RELEASE_VERSION>/
10+
# Updates p2/releases/latest/ composite repository
11+
#
12+
# Required env vars: GITHUB_TOKEN, GITHUB_SHA, GITHUB_REPOSITORY
13+
# Release-only vars: RELEASE_VERSION, SNAPSHOT_SHA
14+
15+
set -euo pipefail
16+
17+
write_composite() {
18+
local dir="$1"
19+
local name="$2"
20+
local child="$3"
21+
rm -rf "$dir"
22+
mkdir -p "$dir"
23+
cat > "$dir/p2.index" << 'EOF'
24+
version=1
25+
metadata.repository.factory.order=compositeContent.xml,\!
26+
artifact.repository.factory.order=compositeArtifacts.xml,\!
27+
EOF
28+
cat > "$dir/compositeContent.xml" << EOF
29+
<?xml version='1.0' encoding='UTF-8'?>
30+
<?compositeMetadataRepository version='1.0.0'?>
31+
<repository name='$name' type='org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository' version='1.0.0'>
32+
<properties size='1'><property name='p2.timestamp' value='$TIMESTAMP'/></properties>
33+
<children size='1'><child location='$child'/></children>
34+
</repository>
35+
EOF
36+
cat > "$dir/compositeArtifacts.xml" << EOF
37+
<?xml version='1.0' encoding='UTF-8'?>
38+
<?compositeArtifactRepository version='1.0.0'?>
39+
<repository name='$name' type='org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository' version='1.0.0'>
40+
<properties size='1'><property name='p2.timestamp' value='$TIMESTAMP'/></properties>
41+
<children size='1'><child location='$child'/></children>
42+
</repository>
43+
EOF
44+
}
45+
46+
cd gh-pages
47+
git config user.email "github-actions[bot]@users.noreply.github.com"
48+
git config user.name "github-actions[bot]"
49+
50+
touch .nojekyll
51+
52+
if [ -n "${RELEASE_VERSION:-}" ]; then
53+
TARGET="p2/releases/$RELEASE_VERSION"
54+
REF_DESC="release $RELEASE_VERSION"
55+
rm -rf "$TARGET"
56+
mkdir -p "$TARGET"
57+
cp -r "p2/snapshots/$SNAPSHOT_SHA/." "$TARGET/"
58+
else
59+
TARGET="p2/snapshots/${GITHUB_SHA::8}"
60+
REF_DESC="snapshot ${GITHUB_SHA::8}"
61+
rm -rf "$TARGET"
62+
mkdir -p "$TARGET"
63+
cp -r ../ddk-repository/target/repository/. "$TARGET/"
64+
fi
65+
66+
TIMESTAMP="$(date +%s)000"
67+
if [ -n "${RELEASE_VERSION:-}" ]; then
68+
HIGHEST=$(ls -1 p2/releases | grep -v latest | sort -Vr | head -1)
69+
write_composite p2/releases/latest "DDK p2 Latest Release" "../$HIGHEST/"
70+
else
71+
SHORT_SHA="${GITHUB_SHA::8}"
72+
write_composite p2/snapshots/latest "DDK p2 Latest Snapshot" "../$SHORT_SHA/"
73+
fi
74+
75+
# Generate index.html
76+
{
77+
echo '<!DOCTYPE html>'
78+
echo '<html><body>'
79+
echo '<h1>DSL DevKit p2 Repository</h1>'
80+
echo '<h2>Snapshots</h2>'
81+
echo '<ul>'
82+
if [ -d p2/snapshots/latest ]; then
83+
echo ' <li><a href="p2/snapshots/latest/">Latest Snapshot</a></li>'
84+
fi
85+
if [ -d p2/snapshots ]; then
86+
for s in $(cd p2/snapshots && ls -1t | grep -v latest | head -20); do
87+
echo " <li><a href=\"p2/snapshots/$s/\">$s</a></li>"
88+
done
89+
fi
90+
echo '</ul>'
91+
if [ -d p2/releases ] && [ -n "$(ls -A p2/releases 2>/dev/null)" ]; then
92+
echo '<h2>Releases</h2>'
93+
echo '<ul>'
94+
if [ -d p2/releases/latest ]; then
95+
echo ' <li><a href="p2/releases/latest/">Latest Release</a></li>'
96+
fi
97+
for v in $(ls -1 p2/releases | grep -v latest | sort -Vr); do
98+
echo " <li><a href=\"p2/releases/$v/\">$v</a></li>"
99+
done
100+
echo '</ul>'
101+
fi
102+
echo '</body></html>'
103+
} > index.html
104+
105+
git add -A
106+
if git diff --cached --quiet; then
107+
echo "No changes to publish"
108+
exit 0
109+
fi
110+
git commit -m "Publish $REF_DESC"
111+
for attempt in 1 2 3; do
112+
if git push origin HEAD:gh-pages; then
113+
exit 0
114+
fi
115+
echo "Push attempt $attempt failed; fetching and rebasing"
116+
git fetch origin gh-pages
117+
git rebase origin/gh-pages
118+
done
119+
echo "Failed to push gh-pages after 3 attempts"
120+
exit 1

.github/workflows/release.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: 'Branch to release from'
8+
required: false
9+
default: master
10+
type: string
11+
version_bump:
12+
description: 'Version component to bump'
13+
required: false
14+
default: patch
15+
type: choice
16+
options:
17+
- patch
18+
- minor
19+
- major
20+
21+
concurrency:
22+
group: publish-ghpages-${{ github.repository }}
23+
cancel-in-progress: false
24+
25+
permissions:
26+
contents: write
27+
28+
jobs:
29+
create_tag:
30+
runs-on: ubuntu-24.04
31+
environment: release
32+
outputs:
33+
tag: ${{ steps.version.outputs.tag }}
34+
snapshot_sha: ${{ steps.snapshot.outputs.sha }}
35+
steps:
36+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
37+
with:
38+
ref: ${{ inputs.branch }}
39+
fetch-depth: 0
40+
41+
- name: Compute next version
42+
id: version
43+
run: |
44+
LATEST=$(git tag --list 'v*' --sort=-version:refname | head -1)
45+
if [ -z "$LATEST" ]; then
46+
LATEST="v0.0.0"
47+
fi
48+
VERSION="${LATEST#v}"
49+
MAJOR=$(echo "$VERSION" | cut -d. -f1)
50+
MINOR=$(echo "$VERSION" | cut -d. -f2)
51+
PATCH=$(echo "$VERSION" | cut -d. -f3)
52+
case "${{ inputs.version_bump }}" in
53+
major) MAJOR=$((MAJOR+1)); MINOR=0; PATCH=0 ;;
54+
minor) MINOR=$((MINOR+1)); PATCH=0 ;;
55+
patch) PATCH=$((PATCH+1)) ;;
56+
esac
57+
NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}"
58+
echo "tag=$NEW_TAG" >> "$GITHUB_OUTPUT"
59+
echo "Previous version $LATEST → next version $NEW_TAG"
60+
61+
- name: Set snapshot SHA
62+
id: snapshot
63+
run: echo "sha=$(git rev-parse --short=8 HEAD)" >> "$GITHUB_OUTPUT"
64+
65+
- name: Check out gh-pages branch
66+
id: checkout-gh-pages
67+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
68+
with:
69+
ref: gh-pages
70+
path: gh-pages
71+
fetch-depth: 1
72+
continue-on-error: true
73+
74+
- name: Verify snapshot exists for release
75+
run: |
76+
SHA="${{ steps.snapshot.outputs.sha }}"
77+
if [ "${{ steps.checkout-gh-pages.outcome }}" != "success" ]; then
78+
echo "::error::gh-pages branch does not exist; no snapshot available for commit $SHA"
79+
exit 1
80+
fi
81+
if [ ! -d "gh-pages/p2/snapshots/$SHA" ]; then
82+
echo "::error::No snapshot found for commit $SHA in p2/snapshots/; the commit must be built and deployed as a snapshot before releasing"
83+
exit 1
84+
fi
85+
echo "Found snapshot for commit $SHA"
86+
87+
- name: Create and push tag
88+
run: |
89+
git config user.name "github-actions[bot]"
90+
git config user.email "github-actions[bot]@users.noreply.github.com"
91+
echo "Bumping to ${{ steps.version.outputs.tag }}"
92+
git tag "${{ steps.version.outputs.tag }}"
93+
git push origin "${{ steps.version.outputs.tag }}"
94+
95+
publish:
96+
needs: create_tag
97+
runs-on: ubuntu-24.04
98+
steps:
99+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
100+
with:
101+
ref: ${{ needs.create_tag.outputs.tag }}
102+
fetch-depth: 0
103+
104+
- name: Check out gh-pages branch
105+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
106+
with:
107+
ref: gh-pages
108+
path: gh-pages
109+
fetch-depth: 1
110+
111+
- name: Publish p2 release to gh-pages
112+
run: bash .github/scripts/publish-p2-ghpages.sh
113+
env:
114+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115+
RELEASE_VERSION: ${{ needs.create_tag.outputs.tag }}
116+
SNAPSHOT_SHA: ${{ needs.create_tag.outputs.snapshot_sha }}
117+
118+
- name: Create release with p2 update site
119+
run: |
120+
RELEASE_VERSION="${{ needs.create_tag.outputs.tag }}"
121+
SNAPSHOT_SHA="${{ needs.create_tag.outputs.snapshot_sha }}"
122+
mkdir -p release-staging/repository
123+
cp -r "gh-pages/p2/snapshots/$SNAPSHOT_SHA/." release-staging/repository/
124+
cd release-staging
125+
zip -r p2-update-site.zip repository/
126+
gh release create "$RELEASE_VERSION" \
127+
p2-update-site.zip \
128+
--generate-notes \
129+
--title "Release ${RELEASE_VERSION#v}"
130+
env:
131+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132+
133+
- name: Summary
134+
run: |
135+
TAG="${{ needs.create_tag.outputs.tag }}"
136+
REPO="${{ github.server_url }}/${{ github.repository }}"
137+
echo "::notice::Created release $TAG from branch ${{ inputs.branch }}"
138+
{
139+
echo "## Release created"
140+
echo ""
141+
echo "| | |"
142+
echo "|---|---|"
143+
echo "| **Tag** | [$TAG]($REPO/releases/tag/$TAG) |"
144+
echo "| **Branch** | \`${{ inputs.branch }}\` |"
145+
echo "| **Bump** | \`${{ inputs.version_bump }}\` |"
146+
} >> "$GITHUB_STEP_SUMMARY"
147+
148+
# Release workflow:
149+
# Snapshots: every push to master or v[0-9]* branches → see snapshot.yml
150+
# Release: workflow_dispatch → create tag, promote snapshot to p2/releases/<version>/
151+
#
152+
# p2 repository URLs (GitHub Pages):
153+
# Latest snapshot: https://dsldevkit.github.io/dsl-devkit/p2/snapshots/latest/
154+
# Pinned snapshot: https://dsldevkit.github.io/dsl-devkit/p2/snapshots/<sha>/
155+
# Latest release: https://dsldevkit.github.io/dsl-devkit/p2/releases/latest/
156+
# Pinned release: https://dsldevkit.github.io/dsl-devkit/p2/releases/{version}/

0 commit comments

Comments
 (0)