Skip to content
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
614721d
chore: Make maven publisher an action
AdamKorcz Jul 26, 2023
a7778a8
fix nits
AdamKorcz Jul 26, 2023
eb64e50
lowercase more variables
AdamKorcz Jul 26, 2023
3e04e30
remove '@'
AdamKorcz Jul 26, 2023
d2cacb8
use secure-project-checkout at main
AdamKorcz Jul 26, 2023
2d1b88a
Nnnnnnnnn (#1)
AdamKorcz Jul 28, 2023
0bf054b
Update README.md
AdamKorcz Jul 28, 2023
e8023f3
Update README.md
AdamKorcz Jul 28, 2023
2581ef9
remove .intoto
AdamKorcz Jul 29, 2023
9b2cae9
remove two more cases of .intoto
AdamKorcz Jul 29, 2023
e23e88e
Update README.md
AdamKorcz Jul 29, 2023
45afa78
Update README.md
AdamKorcz Jul 29, 2023
8cb0d99
Update actions/maven/publish/action.yml
AdamKorcz Jul 31, 2023
aa0ab47
Update actions/maven/publish/action.yml
AdamKorcz Jul 31, 2023
b12e9f3
Install hashing plugin from tool dir (#2)
AdamKorcz Jul 31, 2023
cfd45ea
Add README for Maven publisher
AdamKorcz Jul 31, 2023
effc1d6
Update actions/maven/publish/action.yml
AdamKorcz Aug 1, 2023
16bafbd
Update actions/maven/publish/action.yml
AdamKorcz Aug 1, 2023
9637b4a
Update internal/builders/maven/action.yml
AdamKorcz Aug 1, 2023
0628127
Add flag for maven plugin
AdamKorcz Aug 1, 2023
819ced3
add license header to Mojo
AdamKorcz Aug 1, 2023
8c63c0c
Log error if Mojo cannot create json output file
AdamKorcz Aug 1, 2023
b4204f3
testing latest changes
AdamKorcz Aug 1, 2023
32e3053
Update action.yml
AdamKorcz Aug 1, 2023
b66be39
Update action.yml
AdamKorcz Aug 1, 2023
0067b58
Update action.yml
AdamKorcz Aug 1, 2023
36b7d85
Update action.yml
AdamKorcz Aug 1, 2023
a2303e9
Update actions/maven/publish/action.yml
AdamKorcz Aug 1, 2023
89d60b1
Update actions/maven/publish/action.yml
AdamKorcz Aug 1, 2023
640cc3e
export variables
AdamKorcz Aug 1, 2023
d9f366e
testing exported variables
AdamKorcz Aug 1, 2023
9bee2f4
rename __TOOL_CHECKOUT_DIR__ to __BUILDER_CHECKOUT_DIR__
AdamKorcz Aug 1, 2023
20fa4a7
debug
AdamKorcz Aug 1, 2023
6dae016
Update action.yml
AdamKorcz Aug 1, 2023
4c021a1
Update action.yml
AdamKorcz Aug 1, 2023
7081556
Update action.yml
AdamKorcz Aug 1, 2023
46897c8
Update action.yml
AdamKorcz Aug 1, 2023
fcb67a5
Update action.yml
AdamKorcz Aug 1, 2023
5838ba5
rename Mojo
AdamKorcz Aug 1, 2023
459f39f
rename tool dir to builder dir in maven builder
AdamKorcz Aug 1, 2023
f141f56
remove packages: read
AdamKorcz Aug 1, 2023
0ca0fa3
test
AdamKorcz Aug 1, 2023
d08ce2b
remove hyphen in java package name
AdamKorcz Aug 1, 2023
72c5617
revert debugging helpers
AdamKorcz Aug 1, 2023
f7fa441
Update action.yml
laurentsimon Aug 1, 2023
78a5806
Use v1.8.0 as ref
laurentsimon Aug 1, 2023
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
124 changes: 0 additions & 124 deletions .github/workflows/publish_maven.yml

This file was deleted.

70 changes: 70 additions & 0 deletions actions/maven/publish/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Publishing SLSA3+ provenance to Maven Central

This document explains how to publish SLSA3+ artifacts and provenance to Maven central.

The publish Action is in its early stages and is likely to develop over time. Future breaking changes may occur.

To get started with publishing artifacts to Maven Central Repository, see [this guide](https://maven.apache.org/repository/guide-central-repository-upload.html).

Before you use this publish Action, you will need to configure your Github project with the correct secrets. See [this guide](https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-maven) for more.

## Using the Maven Publish action

To use the Maven action you need to add the step in your release workflow that invokes it.

Before using the Maven publish action, you should have a workflow that invokes the [Maven builder](https://github.com/slsa-framework/slsa-github-generator/blob/main/internal/builders/maven/README.md). It will look something like this:

```yaml
name: Release Maven project
on:
- workflow_dispatch

permissions: read-all

jobs:
build:
permissions:
id-token: write
contents: read
actions: read
packages: read
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
rekor-log-public: true
```

To use the Publish action, you need to add another job:

```yaml
publish:
runs-on: ubuntu-latest
needs: build
permissions:
id-token: write
contents: read
actions: read
steps:
- name: publish
id: publish
uses: slsa-framework/slsa-github-generator/actions/maven/[email protected]
with:
provenance-download-name: "${{ needs.build.outputs.provenance-download-name }}"
provenance-download-sha256: "${{ needs.build.outputs.provenance-download-sha256 }}"
target-download-sha256: "${{ needs.build.outputs.target-download-sha256 }}"
maven-username: ${{ secrets.OSSRH_USERNAME }}
maven-password: ${{ secrets.OSSRH_PASSWORD }}
gpg-key-pass: ${{ secrets.GPG_PASSPHRASE }}
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
```

Set the values of "maven-username", "maven-password", "gpg-key-pass" and " gpg-private-key" for your account. The parameters to `provenance-download-name`, `provenance-download-sha256` and `target-download-sha256` should not be changed.

Once you trigger this workflow, your artifacts and provenance files will be added to a staging repository in Maven Central. You need to close the staging repository and then release:

Closing the staging repository:

![closing the staging repository](/actions/gradle/publish/images/gradle-publisher-staging-repository.png)

Releasing:

![releasing the Gradle artefacts](/actions/gradle/publish/images/gradle-publisher-release-closed-repository.png)
124 changes: 124 additions & 0 deletions actions/maven/publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Copyright 2023 SLSA Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


inputs:
provenance-download-name:
description: "The artifact name for the package provenance."
required: true
type: string
provenance-download-sha256:
description: "The sha256 of the package provenance artifact."
required: true
type: string
target-download-sha256:
description: "The sha256 of the target directory."
required: true
type: string
maven-username:
description: "Maven username"
required: true
maven-password:
description: "Maven password"
required: true
gpg-key-pass:
description: "gpg-key-pass"
required: true
gpg-private-key:
description: "gpg-key-pass"
required: true
runs:
using: "composite"
steps:
- name: Checkout the project repository
uses: slsa-framework/slsa-github-generator/.github/actions/secure-project-checkout@main # needed because we run javadoc and sources.
- name: Set up Java for publishing to Maven Central Repository
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3
env:
MAVEN_USERNAME: ${{ inputs.maven-username }}
MAVEN_PASSWORD: ${{ inputs.maven-password }}
GPG_KEY_PASS: ${{ inputs.gpg-key-pass }}
with:
java-version: '11'
distribution: 'temurin'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ inputs.gpg-private-key }}
gpg-passphrase: GPG_KEY_PASS

- name: Download the slsa attestation
uses: slsa-framework/slsa-github-generator/.github/actions/secure-download-folder@main
with:
name: "${{ inputs.provenance-download-name }}"
path: slsa-attestations
sha256: "${{ inputs.provenance-download-sha256 }}"

- name: Download the target dir
uses: slsa-framework/slsa-github-generator/.github/actions/secure-download-folder@main
with:
name: target
path: ./
sha256: "${{ inputs.target-download-sha256 }}"

- name: Checkout the tool repository
uses: slsa-framework/slsa-github-generator/.github/actions/secure-builder-checkout@main
with:
repository: AdamKorcz/slsa-github-generator
ref: maven-publisher-to-action #main
path: __BUILDER_CHECKOUT_DIR__

- name: Publish to the Maven Central Repository
shell: bash
env:
MAVEN_USERNAME: "${{ inputs.maven-username }}"
MAVEN_PASSWORD: "${{ inputs.maven-password }}"
GPG_KEY_PASS: "${{ inputs.gpg-key-pass }}"
SLSA_DIR: "${{ inputs.provenance-download-name }}"
PROVENANCE_FILES: "${{ inputs.provenance-download-name }}"
run: |
#mv __BUILDER_CHECKOUT_DIR__ ../
find ../.. -name "*.java"
echo "ls"
ls
echo "ls .."
ls ..
echo "ls __BUILDER_CHECKOUT_DIR__"
ls __BUILDER_CHECKOUT_DIR__

cd __BUILDER_CHECKOUT_DIR__/actions/maven/publish/slsa-hashing-plugin && mvn clean install && cd -
Copy link
Collaborator

Choose a reason for hiding this comment

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

better to mve this to ../ to keep the git tree clean (some tools check for that), but we can do that later.

mvn javadoc:jar source:jar
# Retrieve project version
export version=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout)
export artifactid=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.artifactId -q -DforceStdout)
# Reset the environment variables add in the base provenance
export files="slsa-attestations/${PROVENANCE_FILES}/${artifactid}-${version}.jar.build.slsa"
export types=slsa
export classifiers=jar.build
# Find all necessary built jar files and attach them to the environment variable deploy
while read -r name; do
target=$(echo "${name}" | rev | cut -d- -f1 | rev)
files=$files,$name
types=$types,${target##*.}
classifiers=$classifiers,${target%.*}
done <<<"$(find ./ -name "$artifactid-$version-*.jar")"
# Find all generated provenance files and attach them the the environment variable for deploy
while read -r name; do
target=$(echo "${name}" | rev | cut -d- -f1 | rev)
files=$files,$name
types=$types",slsa"
classifiers=$classifiers,${target::-9}
done <<<"$(find ./ -name "$artifactid-$version-*.jar.build.slsa")"
# Sign and deploy the files to the ossrh remote repository
mvn validate jar:jar -Dfile=target/"${artifactid}"-"${version}".jar -Durl=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=ossrh -Dfiles="${files}" -Dtypes="${types}" -Dclassifiers="${classifiers}" -DpomFile=pom.xml gpg:sign-and-deploy-file
42 changes: 42 additions & 0 deletions actions/maven/publish/slsa-hashing-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>dev.slsa.slsaframework</groupId>
<artifactId>hash-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>0.0.1</version>

<name>Jarfile Hashing Maven Mojo</name>
<url>http://maven.apache.org</url>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230227</version>
</dependency>
</dependencies>
</project>
Loading