Skip to content

Commit

Permalink
chore: Use Nix in CI where possible (#5394)
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Al-Istannen authored Aug 29, 2023
1 parent f6ed792 commit fd2c6ab
Show file tree
Hide file tree
Showing 13 changed files with 544 additions and 280 deletions.
29 changes: 29 additions & 0 deletions .github/actions/setup-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Setup test environment

runs:
using: "composite"
steps:
- name: Set git user
shell: bash
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "<>"
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@65d7c888b2778e8cf30a07a88422ccb23499bfb8 # v4
- uses: DeterminateSystems/magic-nix-cache-action@8a218f9e264e9c3803c9a1ee1c30d8e4ab55be63 # v2
- name: Check Nixpkgs inputs
uses: DeterminateSystems/flake-checker-action@4b90f9fc724969ff153fe1803460917c84fe00a3 # v5
with:
fail-mode: true
- name: Use Maven dependency cache
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/.m2/repository
# We use a unique key and restore from the base one, to ensure that
# the cache is updated every time, even if a cache hit was observed.
# See
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
# for more information.
key: ${{ runner.os }}-maven-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-maven
110 changes: 9 additions & 101 deletions .github/workflows/jreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,127 +1,35 @@
name: Release

on:
workflow_dispatch:
workflow_call:
inputs:
version:
description: 'Next release version'
release-script-to-run:
required: true
default: 'patch'
type: choice
options:
- major
- minor
- patch
type: string

jobs:

build:
jreleaser:
runs-on: ubuntu-latest
steps:
# Setups the environment
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
with:
fetch-depth: 0
token: ${{ secrets.JRELEASER_GITHUB_TOKEN }}
- name: Set git user
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
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 }}
- name: Setup env
uses: ./.github/actions/setup-tests

# 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
with:
setup-java: false
version: 1.4.0
arguments: full-release
- name: Do release
run: nix develop .#jReleaser --command ${{ inputs.release-script-to-run }}
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
12 changes: 12 additions & 0 deletions .github/workflows/release-beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Release beta version

on:
schedule:
- cron: '0 0 * * 0' # Sundays at 00:00 (https://crontab.guru/#0_0_*_*_0)

jobs:
snapshot:
uses: ./.github/workflows/jreleaser.yml
with:
release-script-to-run: chore/release-beta.sh
secrets: inherit
21 changes: 21 additions & 0 deletions .github/workflows/release-manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: 'Next release version'
required: true
default: 'patch'
type: choice
options:
- major
- minor
- patch

jobs:
release:
uses: ./.github/workflows/jreleaser.yml
with:
release-script-to-run: chore/release.sh ${{ github.event.inputs.version }}
secrets: inherit
12 changes: 12 additions & 0 deletions .github/workflows/release-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Release nightly version

on:
schedule:
- cron: '0 0 * * *' # Every day at 00:00 UTC (https://crontab.guru/#0_0_*_*_*)

jobs:
nightly:
uses: ./.github/workflows/jreleaser.yml
with:
release-script-to-run: chore/release-nightly.sh
secrets: inherit
Loading

0 comments on commit fd2c6ab

Please sign in to comment.