Skip to content

Commit fa617ff

Browse files
Backport Chocolatey support to Scala LTS (#22095)
Backports #20534 and #21221 to LTS. Requires adaptation - we don't produce native launchers and don't use universal packager plugin [test_chocolatey] --------- Co-authored-by: Hamza Remmal <[email protected]>
1 parent e92d7ec commit fa617ff

11 files changed

+418
-2
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

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
universal-digest:
25+
description: The SHA256 of the uploaded artifact (universal)
26+
value : ${{ jobs.build.outputs.universal-digest }}
27+
28+
29+
jobs:
30+
build:
31+
runs-on: ubuntu-latest
32+
outputs:
33+
universal-id : ${{ steps.universal.outputs.artifact-id }}
34+
universal-digest : ${{ steps.universal-digest.outputs.digest }}
35+
36+
steps:
37+
- uses: actions/checkout@v4
38+
- uses: actions/setup-java@v4
39+
with:
40+
distribution: temurin
41+
java-version: ${{ inputs.java-version }}
42+
cache : sbt
43+
44+
- name: Build and pack the SDK (universal)
45+
run : ./project/scripts/sbt dist/pack
46+
47+
- name: Upload zip archive to GitHub Artifact (universal)
48+
uses: actions/upload-artifact@v4
49+
id : universal
50+
with:
51+
path: ./dist/target/pack/*
52+
name: scala3-universal
53+
54+
- name: Compute SHA256 of the uploaded artifact (universal)
55+
id : universal-digest
56+
run : |
57+
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o artifact.zip -L https://api.github.com/repos/scala/scala3/actions/artifacts/${{ steps.universal.outputs.artifact-id }}/zip
58+
echo "digest=$(sha256sum artifact.zip | cut -d " " -f 1)" >> "$GITHUB_OUTPUT"

.github/workflows/ci.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -774,3 +774,30 @@ jobs:
774774
WORKFLOW_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
775775
with:
776776
filename: .github/workflows/issue_nightly_failed.md
777+
778+
build-sdk-package:
779+
uses: ./.github/workflows/build-sdk.yml
780+
if:
781+
(github.event_name == 'pull_request' && !contains(github.event.pull_request.body, '[skip ci]')) ||
782+
(github.event_name == 'workflow_dispatch' && github.repository == 'scala/scala3') ||
783+
(github.event_name == 'schedule' && github.repository == 'scala/scala3') ||
784+
github.event_name == 'push'
785+
with:
786+
java-version: 8
787+
788+
build-chocolatey-package:
789+
uses: ./.github/workflows/build-chocolatey.yml
790+
needs: [ build-sdk-package ]
791+
with:
792+
version: 3.3.5-local # unused
793+
url : https://api.github.com/repos/scala/scala3/actions/artifacts/${{ needs.build-sdk-package.outputs.universal-id }}/zip
794+
digest : ${{ needs.build-sdk-package.outputs.universal-digest }}
795+
796+
test-chocolatey-package:
797+
uses: ./.github/workflows/test-chocolatey.yml
798+
with:
799+
version : 3.3.5-local # unused
800+
java-version: 8
801+
if: github.event_name == 'pull_request' && contains(github.event.pull_request.body, '[test_chocolatey]')
802+
needs: [ build-chocolatey-package ]
803+
+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

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
name: Releases
1+
###################################################################################################
2+
### OFFICIAL RELEASE WORKFLOW ###
3+
### HOW TO USE: ###
4+
### - THIS WORKFLOW WILL NEED TO BE TRIGGERED MANUALLY ###
5+
### ###
6+
### NOTE: ###
7+
### - THIS WORKFLOW SHOULD ONLY BE RUN ON STABLE RELEASES ###
8+
### - IT ASSUMES THAT THE PRE-RELEASE WORKFLOW WAS PREVIOUSLY EXECUTED ###
9+
### ###
10+
###################################################################################################
11+
12+
name: Official release of Scala
13+
run-name: Official release of Scala ${{ inputs.version }}
14+
215
on:
316
workflow_dispatch:
417
inputs:
@@ -11,7 +24,7 @@ permissions:
1124
contents: read
1225

1326
jobs:
14-
publish_release:
27+
publish-sdkman:
1528
runs-on: [self-hosted, Linux]
1629
container:
1730
image: lampepfl/dotty:2021-03-22
@@ -35,3 +48,35 @@ jobs:
3548

3649
- name: Publish to SDKMAN
3750
run: .github/workflows/scripts/publish-sdkman.sh ${{ inputs.version }}
51+
52+
compute-digest:
53+
runs-on: ubuntu-latest
54+
outputs:
55+
digest: ${{ steps.digest.outputs.digest }}
56+
steps:
57+
- name: Compute the SHA256 of scala3-${{ inputs.version }}.zip in GitHub Release
58+
id: digest
59+
run: |
60+
curl -o artifact.zip -L https://github.com/scala/scala3/releases/download/${{ inputs.version }}/scala3-${{ inputs.version }}.zip
61+
echo "digest=$(sha256sum artifact.zip | cut -d " " -f 1)" >> "$GITHUB_OUTPUT"
62+
63+
build-chocolatey:
64+
uses: ./.github/workflows/build-chocolatey.yml
65+
needs: compute-digest
66+
with:
67+
version: ${{ inputs.version }}
68+
url : 'https://github.com/scala/scala3/releases/download/${{ inputs.version }}/scala3-${{ inputs.version }}.zip'
69+
digest : ${{ needs.compute-digest.outputs.digest }}
70+
test-chocolatey:
71+
uses: ./.github/workflows/test-chocolatey.yml
72+
needs: build-chocolatey
73+
with:
74+
version : ${{ inputs.version }}
75+
java-version: 8
76+
publish-chocolatey:
77+
uses: ./.github/workflows/publish-chocolatey.yml
78+
needs: [ build-chocolatey, test-chocolatey ]
79+
with:
80+
version: ${{ inputs.version }}
81+
secrets:
82+
API-KEY: ${{ secrets.CHOCOLATEY_KEY }}

.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/chocolatey/README.md

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

pkgs/chocolatey/icon.svg

+30
Loading

pkgs/chocolatey/scala.nuspec

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
3+
<metadata>
4+
<id>scala</id>
5+
<version>@LAUNCHER_VERSION@</version>
6+
<title>Scala</title>
7+
<authors>scala</authors>
8+
<owners>scala</owners>
9+
<tags>scala</tags>
10+
<summary>Scala</summary>
11+
<description>Official release of the Scala Programming Language on Chocolatey.</description>
12+
<packageSourceUrl>https://github.com/scala/scala3/tree/main/pkgs/chocolatey</packageSourceUrl>
13+
<projectSourceUrl>https://github.com/scala/scala3</projectSourceUrl>
14+
<projectUrl>https://scala-lang.org/</projectUrl>
15+
<bugTrackerUrl>https://github.com/scala/scala3/issues</bugTrackerUrl>
16+
<copyright>© 2002-2024, LAMP/EPFL</copyright>
17+
<iconUrl>https://cdn.jsdelivr.net/gh/scala/scala3@a046b0014ffd9536144d67a48f8759901b96d12f/pkgs/chocolatey/icon.svg</iconUrl>
18+
<licenseUrl>https://github.com/scala/scala3/blob/main/LICENSE</licenseUrl>
19+
<requireLicenseAcceptance>true</requireLicenseAcceptance>
20+
<releaseNotes>https://github.com/scala/scala3/releases</releaseNotes>
21+
</metadata>
22+
<files>
23+
<file src="tools\**" target="tools" />
24+
</files>
25+
</package>

0 commit comments

Comments
 (0)