Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 95 additions & 1 deletion .github/workflows/java-publish-maven.yml

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot analyze the "-classifier" jobs in this workflow for DRY violations. If sufficient violations exist, remedy them by pulling the common steps into a separate job and making the existing jobs depend on that job. But only do this if you can be 100% sure it is safe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The classifier jobs share checkout and runtime setup, but those steps must execute on each platform-specific runner; a prerequisite job would not transfer its workspace, toolchain, or Maven cache and would only serialize the builds. The remaining build/validation steps intentionally differ by shell and platform hash tool. I therefore made no refactor, as it would add risk without safely removing the duplication.

Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,65 @@ jobs:
echo "tag_commit=$TAG_COMMIT" >> "$GITHUB_OUTPUT"
echo "post_prepare_commit=$POST_PREPARE_COMMIT" >> "$GITHUB_OUTPUT"

build-linux-arm64-classifier:
name: Build Linux ARM64 native classifier
needs: prepare-release
runs-on: ubuntu-24.04-arm
permissions:
contents: read
defaults:
run:
shell: bash
working-directory: ./java
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ needs.prepare-release.outputs.release_tag }}
fetch-depth: 1
persist-credentials: false

- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: "25"
distribution: "microsoft"
cache: "maven"

- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 22

- name: Build and validate linux-arm64 classifier
run: |
set -euo pipefail
SOURCE_COMMIT=$(git rev-parse HEAD)
if [ "$SOURCE_COMMIT" != "${{ needs.prepare-release.outputs.tag_commit }}" ]; then
echo "::error::Checked out $SOURCE_COMMIT instead of the prepared tag commit."
exit 1
fi
node copilot-native/scripts/validate-native-host.mjs linux-arm64
mvn -B -pl copilot-native package -DskipTests -Dcopilot.native.libc=glibc
VERSION="${{ needs.prepare-release.outputs.release_version }}"
JAR="copilot-native/target/copilot-sdk-java-runtime-$VERSION-linux-arm64.jar"
PRIMARY_JAR="copilot-native/target/copilot-sdk-java-runtime-$VERSION.jar"
test -f "$JAR"
node copilot-native/scripts/validate-native-artifact.mjs \
classifier linux-arm64 "$JAR" "$(basename "$JAR")" ..
node copilot-native/scripts/validate-native-artifact.mjs placeholder "$PRIMARY_JAR"
MANIFEST="copilot-native/target/linux-arm64-$VERSION.sha256"
HASH=$(sha256sum "$JAR" | cut -d ' ' -f 1)
printf '%s %s' "$HASH" "$(basename "$JAR")" > "$MANIFEST"
node copilot-native/scripts/validate-native-artifact.mjs \
checksum "$JAR" "$MANIFEST" "$(basename "$JAR")"

- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: java-native-linux-arm64-release-${{ github.run_id }}-${{ github.run_attempt }}
path: |
java/copilot-native/target/copilot-sdk-java-runtime-${{ needs.prepare-release.outputs.release_version }}-linux-arm64.jar
java/copilot-native/target/linux-arm64-${{ needs.prepare-release.outputs.release_version }}.sha256
if-no-files-found: error
retention-days: 1

build-windows-classifier:
name: Build Windows native classifier
needs: prepare-release
Expand Down Expand Up @@ -302,7 +361,13 @@ jobs:

deploy-maven:
name: Deploy Java release to Maven Central
needs: [prepare-release, build-windows-classifier, build-darwin-classifier]
needs:
[
prepare-release,
build-linux-arm64-classifier,
build-windows-classifier,
build-darwin-classifier,
]
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down Expand Up @@ -337,6 +402,11 @@ jobs:
with:
node-version: 22

- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: java-native-linux-arm64-release-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/java-native-linux-arm64

- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: java-native-win32-x64-release-${{ github.run_id }}-${{ github.run_attempt }}
Expand All @@ -347,6 +417,27 @@ jobs:
name: java-native-darwin-arm64-release-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/java-native-darwin-arm64

- name: Verify immutable source and Linux ARM64 classifier
id: linux-arm64-artifact
run: |
SOURCE_COMMIT=$(git rev-parse HEAD)
if [ "$SOURCE_COMMIT" != "${{ needs.prepare-release.outputs.tag_commit }}" ]; then
echo "::error::Checked out $SOURCE_COMMIT instead of the prepared tag commit."
exit 1
fi
VERSION="${{ needs.prepare-release.outputs.release_version }}"
ARTIFACT_DIRECTORY="${{ runner.temp }}/java-native-linux-arm64"
JAR="$ARTIFACT_DIRECTORY/copilot-sdk-java-runtime-$VERSION-linux-arm64.jar"
MANIFEST="$ARTIFACT_DIRECTORY/linux-arm64-$VERSION.sha256"
test -f "$JAR"
test -f "$MANIFEST"
node "$GITHUB_WORKSPACE/java/copilot-native/scripts/validate-native-artifact.mjs" \
checksum "$JAR" "$MANIFEST" "$(basename "$JAR")"
node "$GITHUB_WORKSPACE/java/copilot-native/scripts/validate-native-artifact.mjs" \
classifier linux-arm64 "$JAR" "$(basename "$JAR")" "$GITHUB_WORKSPACE"
echo "linux_arm64_jar=$JAR" >> "$GITHUB_OUTPUT"
echo "linux_arm64_sha=$(cut -d ' ' -f 1 "$MANIFEST")" >> "$GITHUB_OUTPUT"

- name: Verify immutable source and Windows classifier
id: windows-artifact
run: |
Expand Down Expand Up @@ -394,6 +485,7 @@ jobs:
run: |
VERSION="${{ needs.prepare-release.outputs.release_version }}"
mvn -B deploy -DskipTests -Prelease -Dcopilot.native.libc=glibc \
"-Dcopilot.native.external.linux.arm64.classifier.path=${{ steps.linux-arm64-artifact.outputs.linux_arm64_jar }}" \
"-Dcopilot.native.external.win32.classifier.path=${{ steps.windows-artifact.outputs.windows_jar }}" \
"-Dcopilot.native.external.darwin.classifier.path=${{ steps.darwin-artifact.outputs.darwin_jar }}"
LINUX_JAR="copilot-native/target/copilot-sdk-java-runtime-$VERSION-linux-x64.jar"
Expand Down Expand Up @@ -431,6 +523,7 @@ jobs:
echo "| Classifier | Build runner | Artifact | SHA-256 | Status |"
echo "| --- | --- | --- | --- | --- |"
echo "| \`linux-x64\` | \`ubuntu-latest\` | \`$(basename "$LINUX_JAR")\` | \`$LINUX_SHA\` | Published |"
echo "| \`linux-arm64\` | \`ubuntu-24.04-arm\` | \`$(basename "${{ steps.linux-arm64-artifact.outputs.linux_arm64_jar }}")\` | \`${{ steps.linux-arm64-artifact.outputs.linux_arm64_sha }}\` | Published |"
echo "| \`win32-x64\` | \`windows-latest\` | \`$(basename "${{ steps.windows-artifact.outputs.windows_jar }}")\` | \`${{ steps.windows-artifact.outputs.windows_sha }}\` | Published |"
echo "| \`darwin-arm64\` | \`macos-26\` | \`$(basename "${{ steps.darwin-artifact.outputs.darwin_jar }}")\` | \`${{ steps.darwin-artifact.outputs.darwin_sha }}\` | Published |"
} >> "$GITHUB_STEP_SUMMARY"
Expand All @@ -444,6 +537,7 @@ jobs:
needs:
[
prepare-release,
build-linux-arm64-classifier,
build-windows-classifier,
build-darwin-classifier,
deploy-maven,
Expand Down
108 changes: 105 additions & 3 deletions .github/workflows/java-publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,69 @@ jobs:
SHA=$(git rev-parse HEAD)
echo "sha=$SHA" >> "$GITHUB_OUTPUT"

build-linux-arm64-classifier:
name: Build Linux ARM64 snapshot classifier
needs: resolve-source
runs-on: ubuntu-24.04-arm
permissions:
contents: read
outputs:
version: ${{ steps.build.outputs.version }}
defaults:
run:
shell: bash
working-directory: ./java
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.sha }}
fetch-depth: 1
persist-credentials: false

- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: "25"
distribution: "microsoft"
cache: "maven"

- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 22

- name: Build and validate linux-arm64 classifier
id: build
run: |
set -euo pipefail
SOURCE_COMMIT=$(git rev-parse HEAD)
if [ "$SOURCE_COMMIT" != "${{ needs.resolve-source.outputs.source_sha }}" ]; then
echo "::error::Checked out $SOURCE_COMMIT instead of the resolved snapshot source."
exit 1
fi
node copilot-native/scripts/validate-native-host.mjs linux-arm64
mvn -B -pl copilot-native package -DskipTests -Dcopilot.native.libc=glibc
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
JAR="copilot-native/target/copilot-sdk-java-runtime-$VERSION-linux-arm64.jar"
PRIMARY_JAR="copilot-native/target/copilot-sdk-java-runtime-$VERSION.jar"
test -f "$JAR"
node copilot-native/scripts/validate-native-artifact.mjs \
classifier linux-arm64 "$JAR" "$(basename "$JAR")" ..
node copilot-native/scripts/validate-native-artifact.mjs placeholder "$PRIMARY_JAR"
MANIFEST="copilot-native/target/linux-arm64-$VERSION.sha256"
HASH=$(sha256sum "$JAR" | cut -d ' ' -f 1)
printf '%s %s' "$HASH" "$(basename "$JAR")" > "$MANIFEST"
node copilot-native/scripts/validate-native-artifact.mjs \
checksum "$JAR" "$MANIFEST" "$(basename "$JAR")"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: java-native-linux-arm64-snapshot-${{ github.run_id }}-${{ github.run_attempt }}
path: |
java/copilot-native/target/copilot-sdk-java-runtime-${{ steps.build.outputs.version }}-linux-arm64.jar
java/copilot-native/target/linux-arm64-${{ steps.build.outputs.version }}.sha256
if-no-files-found: error
retention-days: 1

build-windows-classifier:
name: Build Windows snapshot classifier
needs: resolve-source
Expand Down Expand Up @@ -160,7 +223,13 @@ jobs:

deploy-snapshot:
name: Publish SNAPSHOT to Maven Central
needs: [resolve-source, build-windows-classifier, build-darwin-classifier]
needs:
[
resolve-source,
build-linux-arm64-classifier,
build-windows-classifier,
build-darwin-classifier,
]
runs-on: ubuntu-latest
defaults:
run:
Expand Down Expand Up @@ -188,6 +257,11 @@ jobs:
with:
node-version: 22

- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: java-native-linux-arm64-snapshot-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/java-native-linux-arm64

- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: java-native-win32-x64-snapshot-${{ github.run_id }}-${{ github.run_attempt }}
Expand All @@ -198,8 +272,8 @@ jobs:
name: java-native-darwin-arm64-snapshot-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/java-native-darwin-arm64

- name: Verify version, source, and Windows classifier
id: windows-artifact
- name: Verify version, source, and Linux ARM64 classifier
id: linux-arm64-artifact
run: |
SOURCE_COMMIT=$(git rev-parse HEAD)
if [ "$SOURCE_COMMIT" != "${{ needs.resolve-source.outputs.source_sha }}" ]; then
Expand All @@ -211,6 +285,32 @@ jobs:
echo "::error::This workflow only publishes SNAPSHOT versions. Current version: $VERSION"
exit 1
fi
if [ "$VERSION" != "${{ needs.build-linux-arm64-classifier.outputs.version }}" ]; then
echo "::error::Linux ARM64 classifier version does not match deploy version."
exit 1
fi
ARTIFACT_DIRECTORY="${{ runner.temp }}/java-native-linux-arm64"
JAR="$ARTIFACT_DIRECTORY/copilot-sdk-java-runtime-$VERSION-linux-arm64.jar"
MANIFEST="$ARTIFACT_DIRECTORY/linux-arm64-$VERSION.sha256"
test -f "$JAR"
test -f "$MANIFEST"
node "$GITHUB_WORKSPACE/java/copilot-native/scripts/validate-native-artifact.mjs" \
checksum "$JAR" "$MANIFEST" "$(basename "$JAR")"
node "$GITHUB_WORKSPACE/java/copilot-native/scripts/validate-native-artifact.mjs" \
classifier linux-arm64 "$JAR" "$(basename "$JAR")" "$GITHUB_WORKSPACE"
echo "linux_arm64_jar=$JAR" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "linux_arm64_sha=$(cut -d ' ' -f 1 "$MANIFEST")" >> "$GITHUB_OUTPUT"

- name: Verify version, source, and Windows classifier
id: windows-artifact
run: |
SOURCE_COMMIT=$(git rev-parse HEAD)
if [ "$SOURCE_COMMIT" != "${{ needs.resolve-source.outputs.source_sha }}" ]; then
echo "::error::Checked out $SOURCE_COMMIT instead of the resolved snapshot source."
exit 1
fi
VERSION="${{ steps.linux-arm64-artifact.outputs.version }}"
if [ "$VERSION" != "${{ needs.build-windows-classifier.outputs.version }}" ]; then
echo "::error::Windows classifier version does not match deploy version."
exit 1
Expand Down Expand Up @@ -257,6 +357,7 @@ jobs:
run: |
VERSION="${{ steps.windows-artifact.outputs.version }}"
mvn -B deploy -DskipTests -Dcopilot.native.libc=glibc \
"-Dcopilot.native.external.linux.arm64.classifier.path=${{ steps.linux-arm64-artifact.outputs.linux_arm64_jar }}" \
"-Dcopilot.native.external.win32.classifier.path=${{ steps.windows-artifact.outputs.windows_jar }}" \
"-Dcopilot.native.external.darwin.classifier.path=${{ steps.darwin-artifact.outputs.darwin_jar }}"
LINUX_JAR="copilot-native/target/copilot-sdk-java-runtime-$VERSION-linux-x64.jar"
Expand Down Expand Up @@ -292,6 +393,7 @@ jobs:
echo "| Classifier | Build runner | Artifact | SHA-256 | Status |"
echo "| --- | --- | --- | --- | --- |"
echo "| \`linux-x64\` | \`ubuntu-latest\` | \`$(basename "$LINUX_JAR")\` | \`$LINUX_SHA\` | Published |"
echo "| \`linux-arm64\` | \`ubuntu-24.04-arm\` | \`$(basename "${{ steps.linux-arm64-artifact.outputs.linux_arm64_jar }}")\` | \`${{ steps.linux-arm64-artifact.outputs.linux_arm64_sha }}\` | Published |"
echo "| \`win32-x64\` | \`windows-latest\` | \`$(basename "${{ steps.windows-artifact.outputs.windows_jar }}")\` | \`${{ steps.windows-artifact.outputs.windows_sha }}\` | Published |"
echo "| \`darwin-arm64\` | \`macos-26\` | \`$(basename "${{ steps.darwin-artifact.outputs.darwin_jar }}")\` | \`${{ steps.darwin-artifact.outputs.darwin_sha }}\` | Published |"
} >> "$GITHUB_STEP_SUMMARY"
Expand Down
Loading
Loading