Skip to content

Commit

Permalink
Implement Chocolatey package with zip not msi
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed Jul 16, 2024
1 parent b3d80e1 commit 4c8f0f7
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-chocolatey.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
search-text: '@LAUNCHER_URL@'
replacement-text: ${{ inputs.url }}
- name: Build the Chocolatey package (.nupkg)
run: choco --pack ./pkgs/chocolatey/scala.nuspec --outputdirectory ./pkgs/chocolatey
run: choco pack ./pkgs/chocolatey/scala.nuspec --out ./pkgs/chocolatey
- name: Upload the Chocolatey package to GitHub
uses: actions/upload-artifact@v4
with:
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/build-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
###################################################################################################
### THIS IS A REUSABLE WORKFLOW TO BUILD THE SCALA LAUNCHERS ###
### HOW TO USE: ###
### - THSI WORKFLOW WILL PACKAGE THE ALL THE LAUNCHERS AND UPLOAD THEM TO GITHUB ARTIFACTS ###
### ###
### NOTE: ###
### - SEE THE WORFLOW FOR THE NAMES OF THE ARTIFACTS ###
###################################################################################################


name: Build Scala Launchers
run-name: Build Scala Launchers

on:
workflow_call:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build and pack the SDK (universal)
run : ./project/scripts/sbt dist/Universal/packageBin
- name: Build and pack the SDK (linux x86-64)
run : ./project/scripts/sbt dist-linux-x86_64/Universal/packageBin
- name: Build and pack the SDK (linux aarch64)
run : ./project/scripts/sbt dist-linux-aarch64/Universal/packageBin
- name: Build and pack the SDK (mac x86-64)
run : ./project/scripts/sbt dist-mac-x86_64/Universal/packageBin
- name: Build and pack the SDK (mac aarch64)
run : ./project/scripts/sbt dist-mac-aarch64/Universal/packageBin
- name: Build and pack the SDK (win x86-64)
run : ./project/scripts/sbt dist-win-x86_64/Universal/packageBin
- name: Upload zip archive to GitHub Artifact (universal)
uses: actions/upload-artifact@v4
with:
path: ./dist/target/universal/scala3-*.zip
name: scala3.zip
- name: Upload zip archive to GitHub Artifact (linux x86-64)
uses: actions/upload-artifact@v4
with:
path: ./dist/linux-x86_64/target/universal/scala3-*-x86_64-pc-linux.zip
name: scala3-x86_64-pc-linux.zip
- name: Upload zip archive to GitHub Artifact (linux aarch64)
uses: actions/upload-artifact@v4
with:
path: ./dist/linux-aarch64/target/universal/scala3-*-aarch64-pc-linux.zip
name: scala3-aarch64-pc-linux.zip
- name: Upload zip archive to GitHub Artifact (mac x86-64)
uses: actions/upload-artifact@v4
with:
path: ./dist/mac-x86_64/target/universal/scala3-*-x86_64-apple-darwin.zip
name: scala3-x86_64-apple-darwin.zip
- name: Upload zip archive to GitHub Artifact (mac aarch64)
uses: actions/upload-artifact@v4
with:
path: ./dist/mac-aarch64/target/universal/scala3-*-aarch64-apple-darwin.zip
name: scala3-aarch64-apple-darwin.zip
- name: Upload zip archive to GitHub Artifact (win x86-64)
uses: actions/upload-artifact@v4
with:
path: ./dist/win-x86_64/target/universal/scala3-*-x86_64-pc-win32.zip
name: scala3-x86_64-pc-win32.zip

7 changes: 5 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1014,13 +1014,16 @@ jobs:
if : github.event_name == 'pull_request' && contains(github.event.pull_request.body, '[test_msi]')
# TODO: ADD A JOB THAT DEPENDS ON THIS TO TEST THE MSI

build-sdk-package:
uses: ./.github/workflows/build-sdk.yml


build-chocolatey-package:
uses: ./.github/workflows/build-chocolatey.yml
needs: [ build-msi-package ]
needs: [ build-sdk-package ]
with:
version: 3.6.0-RC1 # TODO: FIX THIS
url : ${{ needs.build-msi-package.outputs.download-url }}
url : 'https://github.com/scala/scala3/releases/download/3.5.0-RC4/scala3-3.5.0-RC4-x86_64-pc-win32.zip' # TODO: Fix this

test-chocolatey-package:
uses: ./.github/workflows/test-chocolatey.yml
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/test-chocolatey.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ jobs:
- name : Install the `scala` package with Chocolatey
run : choco install scala --source "${{ env.CHOCOLATEY-REPOSITORY }}" --pre # --pre since we might be testing non-stable releases
shell: pwsh
- name : Test the scala command
- name : Test the `scala` command
run : scala --version
shell: pwsh
- name : Test the `scalac` command
run : scalac --version
- name : Test the `scaladoc` command
run : scaladoc --version
- name : Test the `scala-cli` command
run : scala-cli --version
- name : Uninstall the `scala` package
run : choco uninstall scala
30 changes: 24 additions & 6 deletions pkgs/chocolatey/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
$ErrorActionPreference = 'Stop';

$unzipLocation = Split-Path -Parent $MyInvocation.MyCommand.Definition # Get the root of chocolatey folder
$unzipLocation = Join-Path $unzipLocation "$($env:chocolateyPackageName)" # Append the package's name
$unzipLocation = Join-Path $unzipLocation "$($env:chocolateyPackageVersion)" # Append the package's version

# Configure the installation arguments
$packageArgs = @{
packageName = 'scala'
fileType = 'MSI'
url64bit = '@LAUNCHER_URL@'
Url64 = '@LAUNCHER_URL@'
UnzipLocation = $unzipLocation
}

softwareName = 'Scala'
Install-ChocolateyZipPackage @packageArgs

silentArgs = "/qn /norestart"
validExitCodes= @(0)
$extractedDir = Get-ChildItem -Path $unzipLocation | Where-Object { $_.PSIsContainer } | Select-Object -First 1

if (-not $extractedDir) {
throw "Failed to find the extracted directory."
}

Install-ChocolateyPackage @packageArgs
# Define the bin path
$scalaBinPath = Join-Path $unzipLocation $extractedDir | Join-Path -ChildPath 'bin' # Update this path if the structure inside the ZIP changes

# Iterate through the .bat files in the bin directory and create shims
Write-Host "Creating shims for .bat file from $scalaBinPath"
Get-ChildItem -Path $scalaBinPath -Filter '*.bat' | ForEach-Object {
$file = $_.FullName
Write-Host "Creating shim for $file..."
Install-BinFile -Name $_.BaseName -Path $file
}
23 changes: 23 additions & 0 deletions pkgs/chocolatey/tools/chocolateyUninstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$ErrorActionPreference = 'Stop';

$unzipLocation = Split-Path -Parent $MyInvocation.MyCommand.Definition # Get the root of chocolatey folder
$unzipLocation = Join-Path $unzipLocation "$($env:chocolateyPackageName)" # Append the package's name
$unzipLocation = Join-Path $unzipLocation "$($env:chocolateyPackageVersion)" # Append the package's version


$extractedDir = Get-ChildItem -Path $unzipLocation | Where-Object { $_.PSIsContainer } | Select-Object -First 1

if (-not $extractedDir) {
throw "Failed to find the extracted directory."
}

# Define the bin path
$scalaBinPath = Join-Path $unzipLocation $extractedDir | Join-Path -ChildPath 'bin' # Update this path if the structure inside the ZIP changes

# Iterate through the .bat files in the bin directory and remove shims
Write-Host "Removing shims for .bat file from $scalaBinPath"
Get-ChildItem -Path $scalaBinPath -Filter '*.bat' | ForEach-Object {
$file = $_.FullName
Write-Host "Removing shim for $file..."
Uninstall-BinFile -Name $_.BaseName -Path $file
}

0 comments on commit 4c8f0f7

Please sign in to comment.