Skip to content

Commit a046b00

Browse files
authored
Add support for Chocolatey (#20534)
Closes #20380 [test_chocolatey]
2 parents 45dcb51 + 442c0e9 commit a046b00

12 files changed

+464
-0
lines changed
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
###################################################################################################
2+
### THIS IS A REUSABLE WORKFLOW TO BUILD SCALA WITH CHOCOLATEY ###
3+
### HOW TO USE: ###
4+
### ###
5+
### NOTE: ###
6+
### ###
7+
###################################################################################################
8+
9+
10+
name: Build 'scala' Chocolatey Package
11+
run-name: Build 'scala' (${{ inputs.version }}) Chocolatey Package
12+
13+
on:
14+
workflow_call:
15+
inputs:
16+
version:
17+
required: true
18+
type : string
19+
url:
20+
required: true
21+
type : string
22+
digest:
23+
required: true
24+
type : string
25+
26+
jobs:
27+
build:
28+
runs-on: windows-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
- name: Replace the version placeholder
32+
uses: richardrigutins/replace-in-files@v2
33+
with:
34+
files: ./pkgs/chocolatey/scala.nuspec
35+
search-text: '@LAUNCHER_VERSION@'
36+
replacement-text: ${{ inputs.version }}
37+
- name: Replace the URL placeholder
38+
uses: richardrigutins/replace-in-files@v2
39+
with:
40+
files: ./pkgs/chocolatey/tools/chocolateyInstall.ps1
41+
search-text: '@LAUNCHER_URL@'
42+
replacement-text: ${{ inputs.url }}
43+
- name: Replace the CHECKSUM placeholder
44+
uses: richardrigutins/replace-in-files@v2
45+
with:
46+
files: ./pkgs/chocolatey/tools/chocolateyInstall.ps1
47+
search-text: '@LAUNCHER_SHA256@'
48+
replacement-text: ${{ inputs.digest }}
49+
- name: Build the Chocolatey package (.nupkg)
50+
run: choco pack ./pkgs/chocolatey/scala.nuspec --out ./pkgs/chocolatey
51+
- name: Upload the Chocolatey package to GitHub
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: scala.nupkg
55+
path: ./pkgs/chocolatey/scala.${{ inputs.version }}.nupkg
56+
if-no-files-found: error
57+

.github/workflows/build-sdk.yml

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
###################################################################################################
2+
### THIS IS A REUSABLE WORKFLOW TO BUILD THE SCALA LAUNCHERS ###
3+
### HOW TO USE: ###
4+
### - THSI WORKFLOW WILL PACKAGE THE ALL THE LAUNCHERS AND UPLOAD THEM TO GITHUB ARTIFACTS ###
5+
### ###
6+
### NOTE: ###
7+
### - SEE THE WORFLOW FOR THE NAMES OF THE ARTIFACTS ###
8+
###################################################################################################
9+
10+
11+
name: Build Scala Launchers
12+
run-name: Build Scala Launchers
13+
14+
on:
15+
workflow_call:
16+
inputs:
17+
java-version:
18+
type : string
19+
required : true
20+
outputs:
21+
universal-id:
22+
description: ID of the `universal` package from GitHub Artifacts (Authentication Required)
23+
value : ${{ jobs.build.outputs.universal-id }}
24+
linux-x86_64-id:
25+
description: ID of the `linux x86-64` package from GitHub Artifacts (Authentication Required)
26+
value : ${{ jobs.build.outputs.linux-x86_64-id }}
27+
linux-aarch64-id:
28+
description: ID of the `linux aarch64` package from GitHub Artifacts (Authentication Required)
29+
value : ${{ jobs.build.outputs.linux-aarch64-id }}
30+
mac-x86_64-id:
31+
description: ID of the `mac x86-64` package from GitHub Artifacts (Authentication Required)
32+
value : ${{ jobs.build.outputs.mac-x86_64-id }}
33+
mac-aarch64-id:
34+
description: ID of the `mac aarch64` package from GitHub Artifacts (Authentication Required)
35+
value : ${{ jobs.build.outputs.mac-aarch64-id }}
36+
win-x86_64-id:
37+
description: ID of the `win x86-64` package from GitHub Artifacts (Authentication Required)
38+
value : ${{ jobs.build.outputs.win-x86_64-id }}
39+
win-x86_64-digest:
40+
description: The SHA256 of the uploaded artifact (`win x86-64`)
41+
value : ${{ jobs.build.outputs.win-x86_64-digest }}
42+
43+
44+
jobs:
45+
build:
46+
runs-on: ubuntu-latest
47+
outputs:
48+
universal-id : ${{ steps.universal.outputs.artifact-id }}
49+
linux-x86_64-id : ${{ steps.linux-x86_64.outputs.artifact-id }}
50+
linux-aarch64-id : ${{ steps.linux-aarch64.outputs.artifact-id }}
51+
mac-x86_64-id : ${{ steps.mac-x86_64.outputs.artifact-id }}
52+
mac-aarch64-id : ${{ steps.mac-aarch64.outputs.artifact-id }}
53+
win-x86_64-id : ${{ steps.win-x86_64.outputs.artifact-id }}
54+
win-x86_64-digest: ${{ steps.win-x86_64-digest.outputs.digest }}
55+
steps:
56+
- uses: actions/checkout@v4
57+
- uses: actions/setup-java@v4
58+
with:
59+
distribution: temurin
60+
java-version: ${{ inputs.java-version }}
61+
cache : sbt
62+
- name: Build and pack the SDK (universal)
63+
run : ./project/scripts/sbt dist/Universal/stage
64+
- name: Build and pack the SDK (linux x86-64)
65+
run : ./project/scripts/sbt dist-linux-x86_64/Universal/stage
66+
- name: Build and pack the SDK (linux aarch64)
67+
run : ./project/scripts/sbt dist-linux-aarch64/Universal/stage
68+
- name: Build and pack the SDK (mac x86-64)
69+
run : ./project/scripts/sbt dist-mac-x86_64/Universal/stage
70+
- name: Build and pack the SDK (mac aarch64)
71+
run : ./project/scripts/sbt dist-mac-aarch64/Universal/stage
72+
- name: Build and pack the SDK (win x86-64)
73+
run : ./project/scripts/sbt dist-win-x86_64/Universal/stage
74+
- name: Upload zip archive to GitHub Artifact (universal)
75+
uses: actions/upload-artifact@v4
76+
id : universal
77+
with:
78+
path: ./dist/target/universal/stage
79+
name: scala3-universal
80+
- name: Upload zip archive to GitHub Artifact (linux x86-64)
81+
uses: actions/upload-artifact@v4
82+
id : linux-x86_64
83+
with:
84+
path: ./dist/linux-x86_64/target/universal/stage
85+
name: scala3-x86_64-pc-linux
86+
- name: Upload zip archive to GitHub Artifact (linux aarch64)
87+
uses: actions/upload-artifact@v4
88+
id : linux-aarch64
89+
with:
90+
path: ./dist/linux-aarch64/target/universal/stage
91+
name: scala3-aarch64-pc-linux
92+
- name: Upload zip archive to GitHub Artifact (mac x86-64)
93+
uses: actions/upload-artifact@v4
94+
id : mac-x86_64
95+
with:
96+
path: ./dist/mac-x86_64/target/universal/stage
97+
name: scala3-x86_64-apple-darwin
98+
- name: Upload zip archive to GitHub Artifact (mac aarch64)
99+
uses: actions/upload-artifact@v4
100+
id : mac-aarch64
101+
with:
102+
path: ./dist/mac-aarch64/target/universal/stage
103+
name: scala3-aarch64-apple-darwin
104+
- name: Upload zip archive to GitHub Artifact (win x86-64)
105+
uses: actions/upload-artifact@v4
106+
id : win-x86_64
107+
with:
108+
path: ./dist/win-x86_64/target/universal/stage
109+
name: scala3-x86_64-pc-win32
110+
- name: Compute SHA256 of the uploaded artifact (win x86-64)
111+
id : win-x86_64-digest
112+
run : |
113+
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o artifact.zip -L https://api.github.com/repos/scala/scala3/actions/artifacts/${{ steps.win-x86_64.outputs.artifact-id }}/zip
114+
echo "digest=$(sha256sum artifact.zip | cut -d " " -f 1)" >> "$GITHUB_OUTPUT"
115+
116+

.github/workflows/ci.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -1013,3 +1013,24 @@ jobs:
10131013
uses: ./.github/workflows/build-msi.yml
10141014
if : github.event_name == 'pull_request' && contains(github.event.pull_request.body, '[test_msi]')
10151015
# TODO: ADD A JOB THAT DEPENDS ON THIS TO TEST THE MSI
1016+
1017+
build-sdk-package:
1018+
uses: ./.github/workflows/build-sdk.yml
1019+
with:
1020+
java-version: 8
1021+
1022+
build-chocolatey-package:
1023+
uses: ./.github/workflows/build-chocolatey.yml
1024+
needs: [ build-sdk-package ]
1025+
with:
1026+
version: 3.6.0-local # TODO: FIX THIS
1027+
url : https://api.github.com/repos/scala/scala3/actions/artifacts/${{ needs.build-sdk-package.outputs.win-x86_64-id }}/zip
1028+
digest : ${{ needs.build-sdk-package.outputs.win-x86_64-digest }}
1029+
1030+
test-chocolatey-package:
1031+
uses: ./.github/workflows/test-chocolatey.yml
1032+
with:
1033+
version : 3.6.0-local # TODO: FIX THIS
1034+
java-version: 8
1035+
if: github.event_name == 'pull_request' && contains(github.event.pull_request.body, '[test_chocolatey]')
1036+
needs: [ build-chocolatey-package ]
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
###################################################################################################
2+
### THIS IS A REUSABLE WORKFLOW TO PUBLISH SCALA TO CHOCOLATEY ###
3+
### HOW TO USE: ###
4+
### - THE RELEASE WORKFLOW SHOULD CALL THIS WORKFLOW ###
5+
### - IT WILL PUBLISH TO CHOCOLATEY THE MSI ###
6+
### ###
7+
### NOTE: ###
8+
### - WE SHOULD KEEP IN SYNC THE NAME OF THE MSI WITH THE ACTUAL BUILD ###
9+
### - WE SHOULD KEEP IN SYNC THE URL OF THE RELEASE ###
10+
### - IT ASSUMES THAT THE `build-chocolatey` WORKFLOW WAS EXECUTED BEFORE ###
11+
###################################################################################################
12+
13+
14+
name: Publish Scala to Chocolatey
15+
run-name: Publish Scala ${{ inputs.version }} to Chocolatey
16+
17+
on:
18+
workflow_call:
19+
inputs:
20+
version:
21+
required: true
22+
type: string
23+
secrets:
24+
# Connect to https://community.chocolatey.org/profiles/scala
25+
# Accessible via https://community.chocolatey.org/account
26+
API-KEY:
27+
required: true
28+
29+
jobs:
30+
publish:
31+
runs-on: windows-latest
32+
steps:
33+
- name: Fetch the Chocolatey package from GitHub
34+
uses: actions/download-artifact@v4
35+
with:
36+
name: scala.nupkg
37+
- name: Publish the package to Chocolatey
38+
run: choco push scala.nupkg --source https://push.chocolatey.org/ --api-key ${{ secrets.API-KEY }}
39+

.github/workflows/releases.yml

+32
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,36 @@ jobs:
3737
secrets:
3838
DOTTYBOT-TOKEN: ${{ secrets.DOTTYBOT_WINGET_TOKEN }}
3939

40+
compute-digest:
41+
runs-on: ubuntu-latest
42+
outputs:
43+
digest: ${{ steps.digest.outputs.digest }}
44+
steps:
45+
- name: Compute the SHA256 of scala3-${{ inputs.version }}-x86_64-pc-win32.zip in GitHub Release
46+
id: digest
47+
run: |
48+
curl -o artifact.zip -L https://github.com/scala/scala3/releases/download/${{ inputs.version }}/scala3-${{ inputs.version }}-x86_64-pc-win32.zip
49+
echo "digest=$(sha256sum artifact.zip | cut -d " " -f 1)" >> "$GITHUB_OUTPUT"
50+
51+
build-chocolatey:
52+
uses: ./.github/workflows/build-chocolatey.yml
53+
needs: compute-digest
54+
with:
55+
version: ${{ inputs.version }}
56+
url : 'https://github.com/scala/scala3/releases/download/${{ inputs.version }}/scala3-${{ inputs.version }}-x86_64-pc-win32.zip'
57+
digest : ${{ needs.compute-digest.outputs.digest }}
58+
test-chocolatey:
59+
uses: ./.github/workflows/test-chocolatey.yml
60+
needs: build-chocolatey
61+
with:
62+
version : ${{ inputs.version }}
63+
java-version: 8
64+
publish-chocolatey:
65+
uses: ./.github/workflows/publish-chocolatey.yml
66+
needs: [ build-chocolatey, test-chocolatey ]
67+
with:
68+
version: ${{ inputs.version }}
69+
secrets:
70+
API-KEY: ${{ secrets.CHOCOLATEY_KEY }}
71+
4072
# TODO: ADD RELEASE WORKFLOW TO CHOCOLATEY AND OTHER PACKAGE MANAGERS HERE

.github/workflows/test-chocolatey.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
###################################################################################################
2+
### THIS IS A REUSABLE WORKFLOW TO TEST SCALA WITH CHOCOLATEY ###
3+
### HOW TO USE: ###
4+
### ###
5+
### NOTE: ###
6+
### ###
7+
###################################################################################################
8+
9+
name: Test 'scala' Chocolatey Package
10+
run-name: Test 'scala' (${{ inputs.version }}) Chocolatey Package
11+
12+
on:
13+
workflow_call:
14+
inputs:
15+
version:
16+
required: true
17+
type: string
18+
java-version:
19+
required: true
20+
type : string
21+
22+
env:
23+
CHOCOLATEY-REPOSITORY: chocolatey-pkgs
24+
DOTTY_CI_INSTALLATION: ${{ secrets.GITHUB_TOKEN }}
25+
26+
jobs:
27+
test:
28+
runs-on: windows-latest
29+
steps:
30+
- uses: actions/setup-java@v4
31+
with:
32+
distribution: temurin
33+
java-version: ${{ inputs.java-version }}
34+
- name: Download the 'nupkg' from GitHub Artifacts
35+
uses: actions/download-artifact@v4
36+
with:
37+
name: scala.nupkg
38+
path: ${{ env.CHOCOLATEY-REPOSITORY }}
39+
- name : Install the `scala` package with Chocolatey
40+
run : choco install scala --source "${{ env.CHOCOLATEY-REPOSITORY }}" --pre # --pre since we might be testing non-stable releases
41+
shell: pwsh
42+
- name : Test the `scala` command
43+
run : scala --version
44+
shell: pwsh
45+
- name : Test the `scalac` command
46+
run : scalac --version
47+
- name : Test the `scaladoc` command
48+
run : scaladoc --version
49+
- name : Uninstall the `scala` package
50+
run : choco uninstall scala
51+

pkgs/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<h1 align=center>Configuration for Chocolatey</h1>
2+
3+
Official support for Chocolatey started by the release of Scala 3.6.0
4+
5+
> [!IMPORTANT]
6+
> This folder contains the templates to generate the configuration for Chocolatey.
7+
> The `scala.nuspec` and `chocolateyInstall.ps1` files needs to be rewritten by changing the following placeholders:
8+
> - @LAUNCHER_VERSION@ : Placeholder for the current scala version to deploy
9+
> - @LAUNCHER_URL@ : Placeholder for the URL to the windows zip released on GitHub
10+
> - @LAUNCHER_SHA256@ : Placeholder for the SHA256 of the msi file released on GitHub
11+
12+
## Important information
13+
14+
- How to create a *Chocolatey* package: https://docs.chocolatey.org/en-us/create/create-packages/
15+
- Guidelines to follow for the package icon: https://docs.chocolatey.org/en-us/create/create-packages/#package-icon-guidelines
16+
- `.nuspec` format specification: https://learn.microsoft.com/en-gb/nuget/reference/nuspec

pkgs/chocolatey/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<h1 align=center>Configuration for Chocolatey</h1>
2+
3+
Official support for Chocolatey started by the release of Scala 3.6.0
4+
5+
> [!IMPORTANT]
6+
> This folder contains the templates to generate the configuration for Chocolatey.
7+
> The `scala.nuspec` and `chocolateyInstall.ps1` files needs to be rewritten by changing the following placeholders:
8+
> - @LAUNCHER_VERSION@ : Placeholder for the current scala version to deploy
9+
> - @LAUNCHER_URL@ : Placeholder for the URL to the windows zip released on GitHub
10+
> - @LAUNCHER_SHA256@ : Placeholder for the SHA256 of the msi file released on GitHub

pkgs/chocolatey/icon.svg

+30
Loading

0 commit comments

Comments
 (0)