Skip to content
This repository has been archived by the owner on Jun 1, 2020. It is now read-only.

Commit

Permalink
azure pipeline CI to release native macos/windows versions (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroth authored May 10, 2019
1 parent ac1c0a5 commit 2d96673
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 3 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
](https://hub.docker.com/r/mrothy/scalafmt-native)

Statically-linked GraalVM "native image" binaries of [`scalafmt`] packaged for
Docker. These are totally self-contained, start instantly, and do not require
the JVM to run.
Linux, macOS, and Docker. These are totally self-contained, start instantly, and
do not require the JVM to run.

Full size is about 32MB uncompressed.

[`scalafmt`]: https://scalameta.org/scalafmt/

### Usage
### macOS and Linux

Download the latest version from the [releases page](https://github.com/mroth/scalafmt-native/releases/latest).

### Docker
Sample usage running on a local `src` directory:

docker pull mrothy/scalafmt-native
Expand Down
86 changes: 86 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Somse useful references found thus far:
# https://docs.microsoft.com/en-us/azure/devops/pipelines/process/multiple-phases?view=azure-devops&tabs=yaml
# https://github.com/peterheesterman/chit/blob/master/azure-pipelines.yml

variables:
scalafmt_version: v2.0.0-RC7
graalvm_version: 1.0.0-rc16

trigger:
branches:
include:
- refs/heads/*
- refs/tags/*

jobs:
# Initial task to compile a JAR, store as a pipeline artifact to be used by
# downstream builders.
- job: BuildJAR
pool:
vmImage: 'ubuntu-16.04'
steps:
- script: |
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
sudo apt-get update
sudo apt-get install sbt
displayName: Install SBT
- script: |
git clone https://github.com/scalameta/scalafmt --branch ${SCALAFMT_VERSION} --single-branch
cd scalafmt
sbt cli/assembly
displayName: Build scalafmt with assembly into JAR
- task: PublishPipelineArtifact@0
inputs:
targetPath: scalafmt/scalafmt-cli/target/scala-2.12/scalafmt.jar
artifactName: jar

# Parallel native builders using template, each builds on corresponding OS and
# packages into archive, then sends results into artifact pipeline.
- template: ci/native-build.yml
parameters:
name: BuildNative_Linux
platform: linux-amd64
vmImage: ubuntu-16.04
binPath: bin
buildFlags: '--static'

- template: ci/native-build.yml
parameters:
name: BuildNative_macOS
platform: macOS-amd64
vmImage: macOS-10.14
binPath: Contents/Home/bin

# Releaser, gets everything from artifact pipeline, and then uploads to GitHub
# Releases if there is a semver tag.
#
# Currently this requires the GitHub "release" to not already exist due to
# 'create' action usage, TODO: if this can be made to work with 'edit' as well.
# Prior the 'edit' action was not working with 'auto' tag(?).
- job: UploadReleases
dependsOn:
- BuildNative_macOS
- BuildNative_Linux
steps:
- task: DownloadPipelineArtifact@0
inputs:
artifactName: dist_linux-amd64
targetPath: $(Build.ArtifactStagingDirectory)
- task: DownloadPipelineArtifact@0
inputs:
artifactName: dist_macOS-amd64
targetPath: $(Build.ArtifactStagingDirectory)
- script: ls -lh $(Build.ArtifactStagingDirectory)
- task: GithubRelease@0
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
inputs:
gitHubConnection: 'GitHub-mroth-oauth'
repositoryName: 'mroth/scalafmt-native'
action: create
target: '$(Build.SourceVersion)'
tagSource: auto
# By default, all files in the $(Build.ArtifactStagingDirectory) directory will be uploaded.
# assets: '$(Build.ArtifactStagingDirectory)/*.tgz'
assetUploadMode: replace
addChangeLog: true
46 changes: 46 additions & 0 deletions ci/native-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
parameters:
name: ''
platform: linux-amd64 # currently macOS-amd64 or linux-amd64
vmImage: ubuntu-16.04
binPath: bin
buildFlags: '' # any extra build flags requested

jobs:
- job: ${{ parameters.name }}
dependsOn:
- BuildJAR
pool:
vmImage: ${{ parameters.vmImage }}
variables:
platform: ${{ parameters.platform }}
bin_path: ${{ parameters.binPath }}
build_flags: ${{ parameters.buildFlags }}
steps:
- task: DownloadPipelineArtifact@0
inputs:
artifactName: jar
targetPath: $(System.DefaultWorkingDirectory)
- script: |
curl -fsL https://github.com/oracle/graal/releases/download/vm-$(graalvm_version)/graalvm-ce-${GRAALVM_VERSION}-${PLATFORM}.tar.gz \
--output graalvm.tgz
tar xzf graalvm.tgz && rm -rf graalvm.tgz
mv graalvm-ce-$(graalvm_version) graalvm
displayName: Install GraalVM
- script: |
JAVA_OPTS="-Xmx=2g" ./graalvm/${BIN_PATH}/native-image \
${BUILD_FLAGS} \
--no-fallback \
-jar ./scalafmt.jar \
scalafmt-native
ls -lh
displayName: Build ${{ parameters.platform }} native image
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: $(System.DefaultWorkingDirectory)/scalafmt-native
archiveType: 'tar'
tarCompression: 'gz'
archiveFile: '$(Build.ArtifactStagingDirectory)/scalafmt-native_${{ parameters.platform }}.tgz'
- task: PublishPipelineArtifact@0
inputs:
artifactName: dist_${{ parameters.platform }}
targetPath: $(Build.ArtifactStagingDirectory)

1 comment on commit 2d96673

@mroth
Copy link
Owner Author

@mroth mroth commented on 2d96673 May 10, 2019

Choose a reason for hiding this comment

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

My brain broke when writing this commit message. I mean "macos/linux" releases, obviously.

But since this has already been "released" I'm not going to rewrite the commit and force push.

Please sign in to comment.