Skip to content

Commit

Permalink
chore: Grieve
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Al-Istannen committed Aug 26, 2023
1 parent bf2100b commit 74f75b2
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 97 deletions.
102 changes: 15 additions & 87 deletions .github/workflows/jreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ on:
- patch

jobs:

build:
release:
runs-on: ubuntu-latest
steps:
# Setups the environment
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
with:
Expand All @@ -28,100 +26,30 @@ jobs:
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "<>"
- name: Set up JDK 11
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Check Nixpkgs inputs
uses: DeterminateSystems/flake-checker-action@v5
with:
java-version: '11'
distribution: 'temurin'
cache: maven

- name: install go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4
- name: install semversion
run: go install github.com/ffurrer2/semver/cmd/semver@latest
# Get current version from pom and remove snapshot if present.
- name: Get current version from pom and remove snapshot if present.
run: echo "CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT//')" >> $GITHUB_ENV
- name: Get version with snapshot
run: echo "CURRENT_VERSION_WITH_SNAPSHOT=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
# Calculate release version:
# - if `version` is patch, we just increment drop the `-SNAPSHOT` suffix
# (e.g. 10.0.1-SNAPSHOT -> 10.0.1)
# - if `version` is minor or major, we increment the minor or major version and
# set the patch version to `0` (e.g. 10.0.1-SNAPSHOT -> 11.0.0 or 10.1.0)
#
# As we are using a snapshot version, the first call to `semver next` slices
# off only the `-SNAPSHOT` suffix. We therefore run `semver next` on the
# version *without* the `-SNAPSHOT` prefix for major and minor bumps.
#
# After release, we run `semver next` once again and append the `-SNAPSHOT`
# suffix. This results in our patch version from above becoming
# `10.0.2-SNAPSHOT`. The major/minor just get the patch set to `1` and
# `-SNAPSHOT` appended.
- name: Set next version for patch
if: ${{ github.event.inputs.version == 'patch' }}
run: echo "NEXT_VERSION=$(semver next ${{ github.event.inputs.version }} $CURRENT_VERSION_WITH_SNAPSHOT)" >> $GITHUB_ENV
- name: Set next version for major/minor
if: ${{ github.event.inputs.version == 'major' || github.event.inputs.version == 'minor' }}
run: echo "NEXT_VERSION=$(semver next ${{ github.event.inputs.version }} $CURRENT_VERSION)" >> $GITHUB_ENV
- name: set branchname to next version
run: echo "BRANCH_NAME=release/$NEXT_VERSION" >> $GITHUB_ENV
- name: Set release version
run: |
mvn -f spoon-pom --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_VERSION -DprocessAllModules
mvn --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_VERSION -DprocessAllModules
mvn -f spoon-javadoc --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_VERSION -DprocessAllModules
- name: Commit & Push changes
run: |
git checkout -b ${{env.BRANCH_NAME}}
git commit -am "release: Releasing version ${{ env.NEXT_VERSION }}"
git push --set-upstream origin ${{ env.BRANCH_NAME }}
# Now we can run the release
- name: Stage release
run: |
mvn -f spoon-pom --no-transfer-progress --batch-mode -Pjreleaser clean deploy -DaltDeploymentRepository=local::default::file:./target/staging-deploy
mvn --no-transfer-progress --batch-mode -Pjreleaser deploy:deploy-file -Dfile="./spoon-pom/pom.xml" -DpomFile="./spoon-pom/pom.xml" -Durl=file://$(mvn help:evaluate -D"expression=project.basedir" -q -DforceStdout)/target/staging-deploy
- name: Print next version
run: mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT//'
- name: Run JReleaser
uses: jreleaser/release-action@0b198089c53ad2aef0d2bff6b5e6061ead2bbb90 # v2
fail-mode: true
- name: Use Maven dependency cache
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
setup-java: false
version: 1.4.0
arguments: full-release
path: ~/.m2/repository
key: ${{ runner.os }}

- name: Do release
run: nix develop .#jReleaser --command chore/release.sh ${{ github.event.inputs.version }}
env:
JRELEASER_PROJECT_VERSION: ${{ env.NEXT_VERSION }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.JRELEASER_GITHUB_TOKEN }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_NEXUS2_MAVEN_CENTRAL_USERNAME: ${{ secrets.JRELEASER_NEXUS2_MAVEN_CENTRAL_USERNAME }}
JRELEASER_NEXUS2_MAVEN_CENTRAL_PASSWORD: ${{ secrets.JRELEASER_NEXUS2_MAVEN_CENTRAL_PASSWORD }}
# Time to set the next version: The next version of any Release is a snapshot version of the next patch version
- name : Set next version (patch of release version) with -SNAPSHOT suffix
run: |
echo "NEXT_RELEASE_VERSION=$(semver next patch $NEXT_VERSION)-SNAPSHOT" >> $GITHUB_ENV
echo "NEXT_RELEASE_VERSION_WITHOUT_SNAPSHOT=$(semver next patch $NEXT_VERSION)" >> $GITHUB_ENV
- name: Set release version
run: |
mvn -f spoon-pom --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_RELEASE_VERSION -DprocessAllModules
mvn --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_RELEASE_VERSION -DprocessAllModules
mvn -f spoon-javadoc --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_RELEASE_VERSION -DprocessAllModules
# Commit and push changes
- name: Commit & Push changes
run: |
git commit -am "release: Setting SNAPSHOT version $NEXT_RELEASE_VERSION"
git push --set-upstream origin ${{ env.BRANCH_NAME }}
- name: Merge Fast Forward
run: |
git checkout master
git merge --ff-only ${{ env.BRANCH_NAME }}
git push origin master

# Log failure:
# Log failures
- name: JReleaser release output
if: always()
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3
Expand Down
82 changes: 82 additions & 0 deletions chore/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
if [ -z "$1" ]; then
echo "Usage: $0 <patch|major|minor>"
exit 1
fi

# Get current version from pom and remove snapshot if present.
CURRENT_VERSION="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT//')"
CURRENT_VERSION_WITH_SNAPSHOT="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)"

# Calculate release version:
# - if `version` is patch, we just increment drop the `-SNAPSHOT` suffix
# (e.g. 10.0.1-SNAPSHOT -> 10.0.1)
# - if `version` is minor or major, we increment the minor or major version and
# set the patch version to `0` (e.g. 10.0.1-SNAPSHOT -> 11.0.0 or 10.1.0)
#
# As we are using a snapshot version, the first call to `semver next` slices
# off only the `-SNAPSHOT` suffix. We therefore run `semver next` on the
# version *without* the `-SNAPSHOT` prefix for major and minor bumps.
#
# After release, we run `semver next` once again and append the `-SNAPSHOT`
# suffix. This results in our patch version from above becoming
# `10.0.2-SNAPSHOT`. The major/minor just get the patch set to `1` and
# `-SNAPSHOT` appended.

if [[ "$1" == "patch" ]]; then
NEXT_VERSION="$(semver next "$1" "$CURRENT_VERSION_WITH_SNAPSHOT")"
elif [[ "$1" == "minor" ]] || [[ "$1" == "major" ]]; then
NEXT_VERSION="$(semver next "$1" "$CURRENT_VERSION")"
else
echo "Unknown next version '$1'"
exit 1
fi

BRANCH_NAME="release/$NEXT_VERSION"

echo "::group::Setting release version"
mvn -f spoon-pom --no-transfer-progress --batch-mode versions:set -DnewVersion="$NEXT_VERSION" -DprocessAllModules
mvn --no-transfer-progress --batch-mode versions:set -DnewVersion="$NEXT_VERSION" -DprocessAllModules
mvn -f spoon-javadoc --no-transfer-progress --batch-mode versions:set -DnewVersion="$NEXT_VERSION" -DprocessAllModules
echo "::endgroup::"

echo "::group::Commit & Push changes"
git checkout -b "$BRANCH_NAME"
git commit -am "release: Releasing version $NEXT_VERSION"
git push --set-upstream origin "$BRANCH_NAME"
echo "::endgroup::"

echo "::group::Staging release"
mvn -f spoon-pom --no-transfer-progress --batch-mode -Pjreleaser clean deploy -DaltDeploymentRepository=local::default::file:./target/staging-deploy
mvn --no-transfer-progress --batch-mode -Pjreleaser deploy:deploy-file \
-Dfile="./spoon-pom/pom.xml" \
-DpomFile="./spoon-pom/pom.xml" \
-Durl="file://$(mvn help:evaluate -D"expression=project.basedir" -q -DforceStdout)/target/staging-deploy"
echo "::endgroup::"

echo "::group::Next version"
mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT//'
echo "::endgroup::"

echo "::group::Releasing"
JRELEASER_PROJECT_VERSION="$NEXT_VERSION" jreleaser-cli full-release
echo "::endgroup::"

# Set next version (patch of release version) with -SNAPSHOT suffix
NEXT_RELEASE_VERSION="$(semver next patch "$NEXT_VERSION")-SNAPSHOT"

echo "::group::Updating poms to next target version"
mvn -f spoon-pom --no-transfer-progress --batch-mode versions:set -DnewVersion="$NEXT_RELEASE_VERSION" -DprocessAllModules
mvn --no-transfer-progress --batch-mode versions:set -DnewVersion="$NEXT_RELEASE_VERSION" -DprocessAllModules
mvn -f spoon-javadoc --no-transfer-progress --batch-mode versions:set -DnewVersion="$NEXT_RELEASE_VERSION" -DprocessAllModules
echo "::endgroup::"

echo "::group::Committing changes"
git commit -am "release: Setting SNAPSHOT version $NEXT_RELEASE_VERSION"
git push --set-upstream origin "$BRANCH_NAME"
echo "::endgroup::"

echo "::group::Merging into master (fast-forward)"
git checkout master
git merge --ff-only "$BRANCH_NAME"
git push origin master
echo "::endgroup::"
57 changes: 47 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Provide some binary packages for selected system types.
devShells = forAllSystems (system:
let
mkShell = extraCheckPackages: javaVersion:
mkShell = { release ? false, extraChecks ? false, javaVersion }:
let
pkgs = import nixpkgs {
inherit system;
Expand All @@ -31,9 +31,43 @@
z3 = prev.z3.override { inherit jdk; javaBindings = true; };
};
in
(if extraCheckPackages then base // extra else base))
(if extraChecks then base // extra else base))
];
};
semver = pkgs.buildGoModule rec {
name = "semver";
version = "2.1.0";

vendorHash = "sha256-HKqZbgP7vqDJMaHUbSqfSOnBYwzOtIr9o2v/T9S+uNg=";
subPackages = [ "cmd/semver" ];

src = pkgs.fetchFromGitHub {
owner = "ffurrer2";
repo = "semver";
rev = "v${version}";
sha256 = "sha256-i/XPA2Hr2puJFKupIeBUE/yFPJxSeVsDWcz1OepxIcU=";
};
};
jreleaser = pkgs.stdenv.mkDerivation rec {
pname = "jreleaser-cli";
version = "1.7.0";

src = pkgs.fetchurl {
url = "https://github.com/jreleaser/jreleaser/releases/download/v${version}/jreleaser-tool-provider-${version}.jar";
sha256 = "sha256-gr1IWisuep00xyoZWKXtHymWkQjbDhlk6+UC16bKXu0=";
};

nativeBuildInputs = with pkgs; [ makeWrapper ];

dontUnpack = true;

installPhase = ''
mkdir -p $out/share/java/ $out/bin/
cp $src $out/share/java/${pname}.jar
makeWrapper ${pkgs.jdk}/bin/java $out/bin/${pname} \
--add-flags "-jar $out/share/java/${pname}.jar"
'';
};
in
pkgs.mkShell rec {
test = pkgs.writeScriptBin "test" ''
Expand All @@ -58,7 +92,7 @@
mvn -f spoon-pom -B test-compile
mvn -f spoon-pom -Pcoveralls test jacoco:report coveralls:report -DrepoToken=$GITHUB_TOKEN -DserviceName=github -DpullRequest=$PR_NUMBER --fail-never
'';
extra = pkgs.writeScriptBin "extra" (if !extraCheckPackages then "exit 2" else ''
extra = pkgs.writeScriptBin "extra" (if !extraChecks then "exit 2" else ''
set -eu
# Use silent log config
cp chore/logback.xml src/test/resources/
Expand Down Expand Up @@ -129,7 +163,7 @@
./chore/check-javadoc-regressions.py COMPARE_WITH_MASTER
'';
pythonEnv =
if extraCheckPackages then
if extraChecks then
with pkgs; python311.withPackages (ps: [
ps.requests
ps.pygithub
Expand All @@ -138,15 +172,18 @@
else [ ];
packages = with pkgs;
[ jdk maven test coverage mavenPomQuality javadocQuality reproducibleBuilds ]
++ (if extraCheckPackages then [ gradle pythonEnv z3.java z3.lib extra extraRemote ] else [ ]);
};
++ (if extraChecks then [ gradle pythonEnv z3.java z3.lib extra extraRemote ] else [ ])
++ (if release then [ semver jreleaser ] else [ ]);
}
;
in
rec {
default = jdk20;
jdk20 = mkShell false 20;
jdk17 = mkShell false 17;
jdk11 = mkShell false 11;
extraChecks = mkShell true 11;
jdk20 = mkShell { javaVersion = 20; };
jdk17 = mkShell { javaVersion = 17; };
jdk11 = mkShell { javaVersion = 11; };
extraChecks = mkShell { extraChecks = true; javaVersion = 11; };
jReleaser = mkShell { release = true; javaVersion = 11; };
});
};
}

0 comments on commit 74f75b2

Please sign in to comment.