diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..0345dd2 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,123 @@ +name: Build +on: [push] + +# this format from Azure doesnt seem to be supported yet. +# TODO: find these hardcoded values and eliminate with GHA version +# variables: +# scalafmt_version: v2.0.1 +# graalvm_version: '19.1.1' + +jobs: + # Initial task to compile a JAR, store as a pipeline artifact to be used by + # downstream builders. + build-jar: + runs-on: ubuntu-18.04 + steps: + - name: Install SBT + run: | + 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 + - name: Build scalafmt with assembly into JAR + env: + SCALAFMT_VERSION: v2.0.1 + run: | + git clone https://github.com/scalameta/scalafmt --branch ${SCALAFMT_VERSION} --depth 1 + cd scalafmt + sbt cli/assembly + - uses: actions/upload-artifact@v1 + with: + path: scalafmt/scalafmt-cli/target/scala-2.12/scalafmt.jar + name: jar + + # Use GraalVM on Linux to convert JAR to a native linux static binary + native-image-linux: + needs: [build-jar] + runs-on: ubuntu-18.04 + container: + image: oracle/graalvm-ce:19.1.1 + steps: + - name: install native-image + run: gu install native-image + - uses: actions/download-artifact@v1 + with: + name: jar + path: . + # - run: ls -lh + - name: build Linux native image (static) + run: | + native-image \ + --static \ + --no-fallback \ + -jar ./scalafmt.jar \ + scalafmt-native + # - run: ls -lh + - run: tar -cvzf scalafmt-native_linux.tgz ./scalafmt-native + # - run: ls -lh + - uses: actions/upload-artifact@v1 + with: + path: scalafmt-native_linux.tgz + name: scalafmt-native_linux + + # Use GraalVM on macOS to convert JAR to a native macOS binary + native-image-mac: + needs: [build-jar] + runs-on: macOS-10.14 + steps: + - name: download GraalVM release + env: + VERSION: "19.1.1" + PLATFORM: darwin-amd64 + run: | + curl -fsL https://github.com/oracle/graal/releases/download/vm-${VERSION}/graalvm-ce-${PLATFORM}-${VERSION}.tar.gz \ + --output graalvm.tgz + tar xzf graalvm.tgz && rm -rf graalvm.tgz + mv graalvm-ce-${VERSION} graalvm + - name: install native-image + env: + BIN_PATH: Contents/Home/bin + run: ./graalvm/${BIN_PATH}/gu install native-image + - uses: actions/download-artifact@v1 + with: + name: jar + path: . + # - run: ls -lh + - name: Build macOS native image + env: + BIN_PATH: Contents/Home/bin + run: | + ./graalvm/${BIN_PATH}/native-image \ + --no-fallback \ + -jar ./scalafmt.jar \ + scalafmt-native + # - run: ls -lh + - run: tar -cvzf scalafmt-native_macOS.tgz ./scalafmt-native + # - run: ls -lh + - uses: actions/upload-artifact@v1 + with: + path: scalafmt-native_macOS.tgz + name: scalafmt-native_macOS + + # Collate artifacts, upload to GitHub Releases on semver tags + releaser: + needs: [native-image-linux, native-image-mac] + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v1 + with: + name: scalafmt-native_macOS + path: . + - uses: actions/download-artifact@v1 + with: + name: scalafmt-native_linux + path: . + - run: ls -lh + # TODO: generate changelog? or just handle via bump + - name: Release to GitHub + if: startsWith(github.ref, 'refs/tags/v') + uses: softprops/action-gh-release@v1 + with: + files: "scalafmt*.tgz" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index d0c3bbf..dc146df 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # scalafmt-native +[![Build Status](https://github.com/mroth/scalafmt-native/workflows/Build/badge.svg)](https://github.com/mroth/scalafmt-native/actions) [ ![Docker Cloud Automated build](https://img.shields.io/docker/cloud/automated/mrothy/scalafmt-native.svg) ![MicroBadger Size](https://img.shields.io/microbadger/image-size/mrothy/scalafmt-native.svg) diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index ff74682..0000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,86 +0,0 @@ -# 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.1 - graalvm_version: '19.1.1' - -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: darwin-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_darwin-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 diff --git a/ci/native-build.yml b/ci/native-build.yml deleted file mode 100644 index 6f3d732..0000000 --- a/ci/native-build.yml +++ /dev/null @@ -1,51 +0,0 @@ -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-${PLATFORM}-${GRAALVM_VERSION}.tar.gz \ - --output graalvm.tgz - tar xzf graalvm.tgz && rm -rf graalvm.tgz - mv graalvm-ce-$(graalvm_version) graalvm - displayName: Install GraalVM - - script: | - set -e - ./graalvm/${BIN_PATH}/gu install native-image - displayName: Install native-image - - script: | - set -e - 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)