Skip to content

Publish

Publish #13

################################################################################
# Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://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.
#
# SPDX-License-Identifier: Apache-2.0
################################################################################
---
name: Publish
on:
workflow_dispatch:
inputs:
releaseVersion:
description: The version you want to release
required: true
type: string
developmentVersion:
description: The development version to assign after the release
required: true
type: string
auto_release:
description: A switch for automatic release after closing the staging repository
required: false
type: boolean
default: false
# only committers can trigger this
jobs:
publish-maven:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
distribution: temurin
# use the default GitHub runner user for the next steps
# this is needed during deploy, for pushing a tag
- name: Configure Git User
uses: fregante/setup-git-user@v2
# this is necessary because it creates gpg.conf, etc.
- name: List Keys
shell: bash
run: |
gpg -K --keyid-format=long
- name: Import GPG Private Key
shell: bash
run: |
echo "use-agent" >> ~/.gnupg/gpg.conf
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
echo -e "${{ secrets.ORG_GPG_PRIVATE_KEY }}" | gpg --import --batch
for fpr in $(gpg --list-keys --with-colons | awk -F: '/fpr:/ {print $10}' | sort -u);
do
echo -e "5\\ny\\n" | gpg --batch --command-fd 0 --expert --edit-key $fpr trust;
done
# Environment variables used in settings.xml and pom.xml
- name: Publish to Maven
shell: bash
env:
MAVEN_USERNAME: ${{ secrets.ORG_OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.ORG_OSSRH_PASSWORD }}
AUTO_RELEASE_AFTER_CLOSE: ${{ inputs.auto_release }}
GPG_PASSPHRASE: ${{ secrets.ORG_GPG_PASSPHRASE }}
# command summary
# -B/--batch-mode: only display progress and errors
# -U: update snapshot-releases
# -Pci-cd: apply the ci-cd profile (in pom.xml)
# release:prepare (comes from maven-release-plugin)
# release:perform (comes from maven-release-plugin)
# javadoc:jar: checks documentation strings
# source:jar: creates a <lib>-<version>-source.jar
# -s settings.xml: use custom settings file
# -D gpg.passphrase: a system property used by the build process for signing
# -D releaseVersion: set the version you're releasing (will also tag using this)
# -D developmentVersion: set the next dev version
run: |
./mvnw -B -U \
-Pci-cd \
release:prepare \
release:perform \
javadoc:jar \
source:jar \
-s settings.xml \
-D releaseVersion="${{ inputs.releaseVersion }}" \
-D developmentVersion="${{ inputs.developmentVersion }}" \
deploy
# artifact_name is cx-ssi-lib and the version should be the *-SNAPSHOT
# In the next step we'll use the releaseVersion to finalize the upload
- name: Get generated artifact name
shell: bash
run: |
echo "artifact_name=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.artifactId -q -DforceStdout)" >> "$GITHUB_ENV"
echo "artifact_version=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_ENV"
# Use the generated name to supply the input 'path' for the upload,
# but upload the final
# Example:
# input: cx-ssi-lib-0.0.1-SNAPSHOT.jar
# output: cx-ssi-lib-0.0.1.jar
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact_name }}-${{ inputs.releaseVersion }}
path: ./target/${{ env.artifact_name }}-${{ env.artifact_version }}.jar