Skip to content

Commit 8d541ae

Browse files
committed
On branch edburns/80-java-monorepo-add-01
modified: 80-java-monorepo-add-01-remove-before-merge/20260513-prompts.md modified: 80-java-monorepo-add-01-remove-before-merge/dd-2989727-move-java-to-monorepo-plan.md - WIP Phase 0. .github/workflows/java-publish-maven.yml .github/workflows/java-publish-snapshot.yml - Copy over from `copilot-sdk-java-00`. 80-java-monorepo-add-01-remove-before-merge/ghcpsp-90-gpg-key-archive.sh 80-java-monorepo-add-01-remove-before-merge/ghcpsp-90-gpg-key-import.sh - Durable way to hand off the ability to publish to maven central. Currently resides with @edburns.
1 parent eea5444 commit 8d541ae

6 files changed

Lines changed: 906 additions & 16 deletions

File tree

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
name: Publish to Maven Central
2+
3+
env:
4+
# Disable Husky Git hooks in CI to prevent local development hooks
5+
# (e.g., pre-commit formatting checks) from running during automated
6+
# workflows that perform git commits and pushes.
7+
HUSKY: 0
8+
9+
on:
10+
workflow_dispatch:
11+
inputs:
12+
releaseVersion:
13+
description: "Release version (e.g., 1.0.0). If empty, derives from pom.xml by removing -SNAPSHOT"
14+
required: false
15+
type: string
16+
developmentVersion:
17+
description: "Next development version (e.g., 1.0.1-SNAPSHOT). If empty, increments patch version"
18+
required: false
19+
type: string
20+
prerelease:
21+
description: "Is this a prerelease?"
22+
type: boolean
23+
required: false
24+
default: false
25+
26+
permissions:
27+
contents: write
28+
id-token: write
29+
30+
concurrency:
31+
group: publish-maven
32+
cancel-in-progress: false
33+
34+
jobs:
35+
publish-maven:
36+
name: Publish Java SDK to Maven Central
37+
runs-on: ubuntu-latest
38+
outputs:
39+
version: ${{ steps.versions.outputs.release_version }}
40+
steps:
41+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
42+
with:
43+
fetch-depth: 0
44+
token: ${{ secrets.JAVA_RELEASE_TOKEN }}
45+
46+
- name: Configure Git for Maven Release
47+
run: |
48+
git config user.name "github-actions[bot]"
49+
git config user.email "github-actions[bot]@users.noreply.github.com"
50+
51+
- uses: ./.github/actions/setup-copilot
52+
53+
- name: Set up JDK 17
54+
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
55+
with:
56+
java-version: "17"
57+
distribution: "microsoft"
58+
cache: "maven"
59+
server-id: central
60+
server-username: MAVEN_USERNAME
61+
server-password: MAVEN_PASSWORD
62+
gpg-private-key: ${{ secrets.JAVA_GPG_SECRET_KEY }}
63+
gpg-passphrase: JAVA_GPG_PASSPHRASE
64+
65+
- name: Determine versions
66+
id: versions
67+
run: |
68+
CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
69+
echo "Current pom.xml version: $CURRENT_VERSION"
70+
71+
# Determine release version
72+
if [ -n "${{ inputs.releaseVersion }}" ]; then
73+
RELEASE_VERSION="${{ inputs.releaseVersion }}"
74+
else
75+
# Remove -SNAPSHOT suffix if present
76+
RELEASE_VERSION="${CURRENT_VERSION%-SNAPSHOT}"
77+
fi
78+
echo "Release version: $RELEASE_VERSION"
79+
80+
# Determine next development version
81+
if [ -n "${{ inputs.developmentVersion }}" ]; then
82+
DEV_VERSION="${{ inputs.developmentVersion }}"
83+
if [[ "$DEV_VERSION" != *-SNAPSHOT ]]; then
84+
echo "::error::developmentVersion '${DEV_VERSION}' must end with '-SNAPSHOT' (e.g., '${DEV_VERSION}-SNAPSHOT'). The maven-release-plugin requires the next development version to be a snapshot."
85+
exit 1
86+
fi
87+
else
88+
# Split version: supports "0.1.32", "0.1.32-java.0", and "0.1.32-java-preview.0" formats
89+
# Validate RELEASE_VERSION format explicitly to provide clear errors
90+
if ! echo "$RELEASE_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-java(-preview)?\.[0-9]+)?$'; then
91+
echo "Error: RELEASE_VERSION '$RELEASE_VERSION' is invalid. Expected format: M.M.P, M.M.P-java.N, or M.M.P-java-preview.N (e.g., 1.2.3, 1.2.3-java.0, or 1.2.3-java-preview.0)." >&2
92+
exit 1
93+
fi
94+
# Extract the base M.M.P portion (before any qualifier)
95+
BASE_VERSION=$(echo "$RELEASE_VERSION" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
96+
QUALIFIER=$(echo "$RELEASE_VERSION" | sed "s|^${BASE_VERSION}||")
97+
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
98+
NEXT_PATCH=$((PATCH + 1))
99+
DEV_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}${QUALIFIER}-SNAPSHOT"
100+
fi
101+
echo "Next development version: $DEV_VERSION"
102+
103+
echo "release_version=$RELEASE_VERSION" >> $GITHUB_OUTPUT
104+
echo "dev_version=$DEV_VERSION" >> $GITHUB_OUTPUT
105+
106+
echo "### Version Summary" >> $GITHUB_STEP_SUMMARY
107+
echo "- **Release version:** $RELEASE_VERSION" >> $GITHUB_STEP_SUMMARY
108+
echo "- **Next development version:** $DEV_VERSION" >> $GITHUB_STEP_SUMMARY
109+
110+
- name: Update documentation with release version
111+
id: update-docs
112+
run: |
113+
VERSION="${{ steps.versions.outputs.release_version }}"
114+
115+
# Read the reference implementation SDK commit hash that this release is synced to
116+
REFERENCE_IMPL_HASH=$(cat .lastmerge)
117+
REFERENCE_IMPL_SHORT="${REFERENCE_IMPL_HASH:0:7}"
118+
REFERENCE_IMPL_URL="https://github.com/github/copilot-sdk/commit/${REFERENCE_IMPL_HASH}"
119+
echo "Reference implementation SDK sync: ${REFERENCE_IMPL_SHORT} (${REFERENCE_IMPL_URL})"
120+
121+
# Update CHANGELOG.md with release version and Reference implementation sync hash
122+
./.github/scripts/release/update-changelog.sh "${VERSION}" "${REFERENCE_IMPL_HASH}"
123+
124+
# Update version in README.md (supports versions like 1.0.0, 0.1.32-java.0, and 0.3.0-java-preview.0)
125+
sed -i "s|<version>[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\(-java\(-preview\)\{0,1\}\.[0-9][0-9]*\)\{0,1\}</version>|<version>${VERSION}</version>|g" README.md
126+
sed -i "s|copilot-sdk-java:[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\(-java\(-preview\)\{0,1\}\.[0-9][0-9]*\)\{0,1\}|copilot-sdk-java:${VERSION}|g" README.md
127+
128+
# Update snapshot version in README.md
129+
DEV_VERSION="${{ steps.versions.outputs.dev_version }}"
130+
sed -i "s|<version>[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\(-java\(-preview\)\{0,1\}\.[0-9][0-9]*\)\{0,1\}-SNAPSHOT</version>|<version>${DEV_VERSION}</version>|g" README.md
131+
132+
# Update version in jbang-example.java
133+
sed -i "s|copilot-sdk-java:[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\(-java\(-preview\)\{0,1\}\.[0-9][0-9]*\)\{0,1\}|copilot-sdk-java:${VERSION}|g" jbang-example.java
134+
sed -i 's|copilot-sdk-java:${project\.version}|copilot-sdk-java:'"${VERSION}"'|g' jbang-example.java
135+
136+
# Update version in cookbook files (hardcoded for direct GitHub browsing and JBang usage)
137+
find src/site/markdown/cookbook -name "*.md" -type f -exec \
138+
sed -i "s|copilot-sdk-java:[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\(-java\(-preview\)\{0,1\}\.[0-9][0-9]*\)\{0,1\}|copilot-sdk-java:${VERSION}|g" {} \;
139+
140+
# Commit the documentation changes before release:prepare (requires clean working directory)
141+
git add CHANGELOG.md README.md jbang-example.java src/site/markdown/cookbook/
142+
git commit -m "docs: update version references to ${VERSION}"
143+
144+
# Save the commit SHA for potential rollback
145+
echo "docs_commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
146+
147+
git push origin main
148+
149+
- name: Prepare Release
150+
run: |
151+
mvn -B release:prepare \
152+
-DreleaseVersion=${{ steps.versions.outputs.release_version }} \
153+
-DdevelopmentVersion=${{ steps.versions.outputs.dev_version }} \
154+
-DtagNameFormat=v@{project.version} \
155+
-DpushChanges=true \
156+
-Darguments="-DskipTests"
157+
env:
158+
MAVEN_USERNAME: ${{ secrets.JAVA_MAVEN_CENTRAL_USERNAME }}
159+
MAVEN_PASSWORD: ${{ secrets.JAVA_MAVEN_CENTRAL_PASSWORD }}
160+
JAVA_GPG_PASSPHRASE: ${{ secrets.JAVA_GPG_PASSPHRASE }}
161+
162+
- name: Perform Release and Deploy to Maven Central
163+
run: |
164+
mvn -B release:perform \
165+
-Dgoals="deploy" \
166+
-Darguments="-DskipTests -Prelease"
167+
env:
168+
MAVEN_USERNAME: ${{ secrets.JAVA_MAVEN_CENTRAL_USERNAME }}
169+
MAVEN_PASSWORD: ${{ secrets.JAVA_MAVEN_CENTRAL_PASSWORD }}
170+
JAVA_GPG_PASSPHRASE: ${{ secrets.JAVA_GPG_PASSPHRASE }}
171+
172+
- name: Rollback documentation commit on failure
173+
if: failure() && steps.update-docs.outputs.docs_commit_sha != ''
174+
run: |
175+
echo "Release failed, rolling back documentation commit..."
176+
git revert --no-edit ${{ steps.update-docs.outputs.docs_commit_sha }}
177+
git push origin main
178+
179+
# Also run Maven release:rollback to clean up any partial release state
180+
mvn -B release:rollback || true
181+
182+
github-release:
183+
name: Create GitHub Release
184+
needs: publish-maven
185+
if: github.ref == 'refs/heads/main'
186+
runs-on: ubuntu-latest
187+
steps:
188+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
189+
with:
190+
fetch-depth: 0
191+
- name: Create GitHub Release
192+
run: |
193+
VERSION="${{ needs.publish-maven.outputs.version }}"
194+
GROUP_ID="com.github"
195+
ARTIFACT_ID="copilot-sdk-java"
196+
CURRENT_TAG="v${VERSION}"
197+
198+
if gh release view "${CURRENT_TAG}" >/dev/null 2>&1; then
199+
echo "Release ${CURRENT_TAG} already exists. Skipping creation."
200+
exit 0
201+
fi
202+
203+
# Generate release notes from template
204+
export VERSION GROUP_ID ARTIFACT_ID
205+
RELEASE_NOTES=$(envsubst < .github/workflows/notes.template)
206+
207+
# Get the previous tag for generating notes
208+
PREV_TAG=$(git tag --list 'v*' --sort=-version:refname \
209+
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-java(-preview)?\.[0-9]+)?$' \
210+
| grep -Fxv "${CURRENT_TAG}" \
211+
| head -n 1)
212+
213+
echo "Current tag: ${CURRENT_TAG}"
214+
echo "Previous tag: ${PREV_TAG}"
215+
216+
# Build the gh release command
217+
GH_ARGS=("${CURRENT_TAG}")
218+
GH_ARGS+=("--title" "GitHub Copilot SDK for Java ${VERSION}")
219+
GH_ARGS+=("--notes" "${RELEASE_NOTES}")
220+
GH_ARGS+=("--generate-notes")
221+
222+
if [ -n "$PREV_TAG" ]; then
223+
GH_ARGS+=("--notes-start-tag" "$PREV_TAG")
224+
fi
225+
226+
${{ inputs.prerelease == true && 'GH_ARGS+=("--prerelease")' || '' }}
227+
228+
gh release create "${GH_ARGS[@]}"
229+
env:
230+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
231+
232+
- name: Move 'latest' tag to new release
233+
run: |
234+
VERSION="${{ needs.publish-maven.outputs.version }}"
235+
git tag -f latest "v${VERSION}"
236+
git push origin latest --force
237+
env:
238+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
239+
240+
deploy-site:
241+
name: Deploy Documentation
242+
needs: [publish-maven, github-release]
243+
runs-on: ubuntu-latest
244+
permissions:
245+
actions: write
246+
contents: read
247+
steps:
248+
- name: Trigger site deployment
249+
run: |
250+
gh workflow run deploy-site.yml \
251+
--repo ${{ github.repository }} \
252+
-f version="${{ needs.publish-maven.outputs.version }}" \
253+
-f publish_as_latest=true
254+
env:
255+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
256+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Publish Snapshot to Maven Central
2+
3+
env:
4+
HUSKY: 0
5+
6+
on:
7+
schedule:
8+
- cron: "0 7 * * 1-5" # Mon-Fri at 07:00 UTC
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
14+
concurrency:
15+
group: publish-snapshot
16+
cancel-in-progress: false
17+
18+
jobs:
19+
publish-snapshot:
20+
name: Publish SNAPSHOT to Maven Central
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
24+
with:
25+
fetch-depth: 0
26+
27+
- uses: ./.github/actions/setup-copilot
28+
29+
- name: Set up JDK 17
30+
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
31+
with:
32+
java-version: "17"
33+
distribution: "microsoft"
34+
cache: "maven"
35+
server-id: central
36+
server-username: MAVEN_USERNAME
37+
server-password: MAVEN_PASSWORD
38+
39+
- name: Verify version is a SNAPSHOT
40+
run: |
41+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
42+
echo "Publishing version: $VERSION"
43+
if [[ "$VERSION" != *"-SNAPSHOT" ]]; then
44+
echo "ERROR: This workflow only publishes SNAPSHOT versions. Current version: $VERSION"
45+
exit 1
46+
fi
47+
echo "### Snapshot Publish" >> $GITHUB_STEP_SUMMARY
48+
echo "- **Version:** $VERSION" >> $GITHUB_STEP_SUMMARY
49+
echo "- **Repository:** Maven Central Snapshots" >> $GITHUB_STEP_SUMMARY
50+
51+
- name: Deploy Snapshot
52+
run: mvn -B deploy -DskipTests
53+
env:
54+
MAVEN_USERNAME: ${{ secrets.JAVA_MAVEN_CENTRAL_USERNAME }}
55+
MAVEN_PASSWORD: ${{ secrets.JAVA_MAVEN_CENTRAL_PASSWORD }}

0 commit comments

Comments
 (0)