Skip to content

Release to Github with Jreleaser #12

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

Merged
merged 2 commits into from
Feb 4, 2022
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
11 changes: 4 additions & 7 deletions .github/workflows/ci.yml → .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: ci
on:
push:
branches:
- master
pull_request:
branches:
- master
Expand All @@ -28,11 +25,11 @@ jobs:
with:
command: fmt
args: --all -- --check
- name: Test
- name: Check compilation
uses: actions-rs/cargo@v1
with:
command: test
- name: Build
command: check
- name: Test
uses: actions-rs/cargo@v1
with:
command: build
command: test
109 changes: 109 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Release

on:
push:
branches: [ main ]

jobs:
precheck:
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.vars.outputs.VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Version
id: vars
shell: bash
run: |
version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't be something like workflow_dispatch cleaner than extracting the version from the Cargo.toml file?

Something like

  workflow_dispatch:
    inputs:
      version:
        description: Release version
        required: true

Copy link
Contributor

Choose a reason for hiding this comment

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

It depends. If you pass the version as a workflow input don't you still have to update Cargo.toml and Cargo.lock before compilation?

Copy link
Member Author

@marc0der marc0der Feb 4, 2022

Choose a reason for hiding this comment

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

Yes, I did this on purpose because in Rust projects the Cargo.toml masters of the version. The sed does feel a bit hacky though 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

If Cargo.toml is the source of truth wrt versioning then the GH action must read the version from there. We could use a different mechanism to extract the version tho.

Copy link
Member

Choose a reason for hiding this comment

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

Yuck! And there is no way to pass in the version. Even good ol' Maven allows this.

rust-lang/cargo#6583

echo ::set-output name=VERSION::$(echo "$version")
build:
needs: [ precheck ]
name: 'Build ${{ matrix.job.target }}'
strategy:
fail-fast: true
matrix:
job:
- { target: aarch64-apple-darwin , os: macos-latest , jreleaser_platform: osx-aarch_64 }
- { target: x86_64-apple-darwin , os: macos-latest , jreleaser_platform: osx-x86_64 }
- { target: x86_64-pc-windows-msvc , os: windows-latest, jreleaser_platform: windows-x86_64 }
- { target: x86_64-unknown-linux-gnu , os: ubuntu-latest , jreleaser_platform: linux-x86_64 }
- { target: aarch64-unknown-linux-gnu, os: ubuntu-latest , use-cross: true, jreleaser_platform: linux-aarch_64 }
runs-on: ${{ matrix.job.os }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.job.target }}
override: true
profile: minimal

- uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use-cross }}
command: build
args: --locked --release --target=${{ matrix.job.target }}

- name: Assemble
uses: jreleaser/release-action@v2
with:
version: early-access
arguments: assemble
env:
JRELEASER_PROJECT_VERSION: ${{ needs.precheck.outputs.VERSION }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JRELEASER_PLATFORM_OVERRIDE: ${{ matrix.job.jreleaser_platform }}

- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
retention-days: 1
name: artifacts
path: |
out/jreleaser/assemble/sdkman/archive/*.zip
- name: JReleaser output
if: always()
uses: actions/upload-artifact@v2
with:
retention-days: 1
name: jreleaser-${{ matrix.job.target }}
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties
release:
needs: [ precheck, build ]
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Download artifacts
uses: actions/download-artifact@v2

- name: Release
uses: jreleaser/release-action@v2
with:
version: early-access
arguments: release -PartifactsDir=artifacts -PskipArchiveResolver
env:
JRELEASER_PROJECT_VERSION: ${{ needs.precheck.outputs.VERSION }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: JReleaser output
if: always()
uses: actions/upload-artifact@v2
with:
retention-days: 1
name: jreleaser-release
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties
71 changes: 71 additions & 0 deletions jreleaser.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[environment.properties]
artifactsDir = "out/jreleaser/assemble/sdkman/archive"

[project]
name = "sdkman"
description = "SDKMAN! native extensions"
longDescription = "Supplementary native extension binaries to replace SDKMAN! bash functions."
website = "https://github.com/sdkman/sdkman-native-cli"
authors = ["Marco Vermeulen", "Oliver Weiler"]
license = "Apache 2.0"

[project.extraProperties]
inceptionYear = 2021

[platform.replacements]
osx-x86_64 = "x86_64-apple-darwin"
osx-aarch_64 = "aarch64-apple-darwin"
linux-x86_64 = "x86_64-unknown-linux-gnu"
linux-aarch_64 = "aarch64-unknown-linux-gnu"
windows-x86_64 = "x86_64-pc-windows-msvc"

[release.github]
overwrite = true

[release.github.changelog]
formatted = "ALWAYS"
format = "- {{commitShortHash}} {{commitTitle}}"
preset = "conventional-commits"

[release.github.changelog.contributors]
format = "- {{contributorName}}{{#contributorUsernameAsLink}} ({{.}}){{/contributorUsernameAsLink}}"

[assemble.archive.sdkman]
active = "ALWAYS"
formats = ["ZIP"]
attachPlatform = true

[[assemble.archive.sdkman.fileSets]]
input = "target/{{ osPlatformReplaced }}/release"
output = "bin"
includes = ["sdkman{.exe,}"]

[[assemble.archive.sdkman.fileSets]]
input = "."
includes = ["LICENSE"]

[distributions.sdkman]
type = "BINARY"

[distributions.sdkman.executable]
windowsExtension = "exe"

[[distributions.sdkman.artifacts]]
path = "{{artifactsDir}}/{{distributionName}}-{{projectVersion}}-aarch64-apple-darwin.zip"
platform = "osx-aarch_64"

[[distributions.sdkman.artifacts]]
path = "{{artifactsDir}}/{{distributionName}}-{{projectVersion}}-x86_64-apple-darwin.zip"
platform = "osx-x86_64"

[[distributions.sdkman.artifacts]]
path = "{{artifactsDir}}/{{distributionName}}-{{projectVersion}}-x86_64-pc-windows-msvc.zip"
platform = "windows-x86_64"

[[distributions.sdkman.artifacts]]
path = "{{artifactsDir}}/{{distributionName}}-{{projectVersion}}-x86_64-unknown-linux-gnu.zip"
platform = "linux-x86_64"

[[distributions.sdkman.artifacts]]
path = "{{artifactsDir}}/{{distributionName}}-{{projectVersion}}-aarch64-unknown-linux-gnu.zip"
platform = "linux-aarch_64"