Skip to content

Commit 0599c3f

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 0599c3f

6 files changed

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

0 commit comments

Comments
 (0)