Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use jreleaser, remove release-drafter. #279

Merged
merged 3 commits into from
Dec 11, 2023
Merged
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
29 changes: 29 additions & 0 deletions .github/actions/increase-semver/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Increase semantic version'
description: 'Increases '
inputs:
current-version:
description: 'The current semantic version string'
required: true
version-fragment:
description: 'The version fragment to increase'
required: false
default: 'minor'
outputs:
next-version:
description: "The next semantic version string with the specific fragment being increased"
value: ${{ steps.increase-semver.outputs.next-version }}
runs:
using: "composite"
steps:
- uses: actions/setup-python@b64ffcaf5b410884ad320a9cfac8866006a109aa # v4.8.0
with:
python-version: '3.10'
cache: 'pip'
- shell: bash
run: pip install -r $GITHUB_ACTION_PATH/requirements.txt
- id: increase-semver
shell: bash
run: |
NEXT_VERSION=$(cd $GITHUB_ACTION_PATH && python increase_semver.py ${{ inputs.current-version }} ${{ inputs.version-fragment }})
echo "Next Version: $NEXT_VERSION"
echo "next-version=${NEXT_VERSION}" >> $GITHUB_OUTPUT
26 changes: 26 additions & 0 deletions .github/actions/increase-semver/increase_semver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# *******************************************************************************
# Copyright (c) 2023 Eclipse Foundation and others.
# This program and the accompanying materials are made available
# under the terms of the MIT License
# which is available at https://spdx.org/licenses/MIT.html
# SPDX-License-Identifier: MIT
# *******************************************************************************

import sys
from semver.version import Version


def run(current_version: str, version_fragment: str) -> None:
v = Version.parse(current_version)
print(str(v.next_version(part=version_fragment)))


if __name__ == "__main__":
args = sys.argv[1:]

if len(args) != 2:
print("Error: Need to provide 2 arguments: 'current-version' and 'version-fragment'.")
exit(1)

run(args[0], args[1])
exit(0)
1 change: 1 addition & 0 deletions .github/actions/increase-semver/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semver==3.0.2
1 change: 0 additions & 1 deletion .github/release-drafter.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/release-drafter.yml

This file was deleted.

156 changes: 90 additions & 66 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true
version-fragment:
description: 'Version fragment to increase for next development cycle'
required: true
default: 'minor'
type: choice
options:
- major
- minor
- patch

env:
BOT_USER_NAME: eclipse-cbi-bot
BOT_EMAIL: [email protected]
JAVA_VERSION: '17'
JAVA_VERSION: 17
JAVA_DISTRO: 'temurin'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: # added using https://github.com/step-security/secure-repo
contents: read
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-latest
# don't run this workflow in forks
if: github.repository == 'eclipse-cbi/macos-notarization-service'
precheck:
runs-on: ubuntu-22.04
permissions:
contents: write
if: github.repository == 'eclipse-cbi/macos-notarization-service'
outputs:
tag: ${{ steps.retrieve-tag.outputs.tag }}
hash: ${{ steps.hash.outputs.hash }}
release-version: ${{ steps.prepare-release.outputs.RELEASE_VERSION }}
steps:
- name: Check ref
shell: bash
run: |
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
echo "Release shall only be made from 'main' branch, triggered branch '${{ github.ref_name }}', aborting."
exit 1
fi

- name: Setup Git User
run: |
git config --global user.name '${{ env.BOT_USER_NAME }}'
Expand All @@ -34,6 +50,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ github.ref }}
fetch-depth: 0

- name: Setup Java
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
Expand All @@ -42,70 +59,77 @@ jobs:
distribution: ${{ env.JAVA_DISTRO }}
cache: maven

- name: Build Release
- name: Prepare release
id: prepare-release
shell: bash
run: |
./mvnw -ntp -B -Prelease release:clean release:prepare -Dmaven.test.skip=true
./mvnw -ntp -B -Pdist -Prelease -Psbom release:perform -Darguments="-Dmaven.deploy.skip=true" -Dgoals=package
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PROJECT_VERSION="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)"
RELEASE_VERSION="${{ github.event.inputs.version }}"

- id: retrieve-tag
run: |
echo "tag=$(git describe --tags --abbrev=0)" >> "$GITHUB_OUTPUT"

- if: cancelled() || failure()
run: ./mvnw -B -Prelease release:rollback
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
echo "PROJECT_VERSION=$(echo $PROJECT_VERSION)" >> $GITHUB_OUTPUT
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT

echo "Project version: $PROJECT_VERSION"
echo "Release version: $RELEASE_VERSION"

if git show-ref --tags --verify --quiet "refs/tags/v${RELEASE_VERSION}"; then
echo "Release Tag 'v${RELEASE_VERSION}' already exists, aborting."
exit 1
fi

if [ "$PROJECT_VERSION" != "$RELEASE_VERSION" ]; then
./mvnw -B versions:set versions:commit -DnewVersion=$RELEASE_VERSION
git commit -a -m "Releasing version $RELEASE_VERSION"
git push origin ${{ github.ref }}
fi

# Generate hashes used for provenance.
- name: generate hash
id: hash
run: cd target/checkout/target/distributions && echo "hash=$(sha256sum * | base64 -w0)" >> $GITHUB_OUTPUT

- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
path: target/checkout/target/distributions


update_release_draft:
needs: ['build']
release:
needs: ['precheck']
permissions:
contents: write
pull-requests: read
runs-on: ubuntu-latest
steps:
# Update the release notes for the released version
- uses: release-drafter/release-drafter@09c613e259eb8d4e7c81c2cb00618eb5fc4575a7 # v5.25.0
with:
tag: ${{ needs.build.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

provenance:
needs: ['build']
permissions:
actions: read
packages: write
id-token: write
contents: write
# Can't pin with hash due to how this workflow works.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
uses: jreleaser/release-action/.github/workflows/builder_slsa3.yml@java
with:
base64-subjects: ${{ needs.build.outputs.hash }}
project-version: ${{ needs.precheck.outputs.release-version }}
branch: ${{ github.ref_name }}
jreleaser-version: '1.9.0'
java-version: 17
java-distribution: 'temurin'
rekor-log-public: true
secrets:
github-token: ${{ secrets.GITHUB_TOKEN }}

upload-artifacts:
# Upload the distribution and provenance to a GitHub release. They remain
# available as build artifacts for a while as well.
needs: ['build', 'provenance', 'update_release_draft']
runs-on: ubuntu-latest
prepare-for-next-development-cycle:
runs-on: ubuntu-22.04
needs: ['precheck', 'release']
permissions:
contents: write
steps:
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
- name: upload artifacts to release
run: >
gh release upload --repo ${{ github.repository }}
${{ needs.build.outputs.tag }}
*.intoto.jsonl/* artifact/*
env:
GH_TOKEN: ${{ github.token }}
- name: Setup Git User
run: |
git config --global user.name '${{ env.BOT_USER_NAME }}'
git config --global user.email '${{ env.BOT_EMAIL }}'

- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ github.ref }}

- name: Setup Java
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRO }}
cache: maven

- id: increase-semver
uses: ./.github/actions/increase-semver
with:
current-version: ${{ needs.precheck.outputs.release-version }}
version-fragment: ${{ github.event.inputs.version-fragment }}
- name: Update next development version in POMs
run: |
./mvnw -B versions:set versions:commit -DnewVersion=${{ steps.increase-semver.outputs.next-version }}-SNAPSHOT -DgenerateBackupPoms=false
git commit -a -m "Prepare for next development cycle"
git push origin ${{ github.ref }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.classpath
.settings/
bin/
out/

# IntelliJ
.idea
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.outputTimestamp>1698421459</project.build.outputTimestamp>
<project.build.outputTimestamp>1702162494</project.build.outputTimestamp>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.parameters>true</maven.compiler.parameters>
Expand Down