Skip to content

Commit fa02725

Browse files
committed
Merge remote-tracking branch 'upstream/main' into suggest-clear-cache-after-dependency-update
2 parents 83b77aa + dd80852 commit fa02725

File tree

13 files changed

+155683
-155891
lines changed

13 files changed

+155683
-155891
lines changed

.github/workflows/e2e-cache.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,99 @@ jobs:
111111
exit 1
112112
fi
113113
ls ~/.m2/repository
114+
sbt-save:
115+
runs-on: ${{ matrix.os }}
116+
defaults:
117+
run:
118+
shell: bash
119+
working-directory: __tests__/cache/sbt
120+
strategy:
121+
fail-fast: false
122+
matrix:
123+
os: [macos-latest, windows-latest, ubuntu-latest]
124+
steps:
125+
- name: Checkout
126+
uses: actions/checkout@v3
127+
- name: Run setup-java with the cache for sbt
128+
uses: ./
129+
id: setup-java
130+
with:
131+
distribution: 'adopt'
132+
java-version: '11'
133+
cache: sbt
134+
- name: Create files to cache
135+
run: sbt update
136+
137+
- name: Check files to cache on macos-latest
138+
if: matrix.os == 'macos-latest'
139+
run: |
140+
if [ ! -d ~/Library/Caches/Coursier ]; then
141+
echo "::error::The ~/Library/Caches/Coursier directory does not exist unexpectedly"
142+
exit 1
143+
fi
144+
145+
- name: Check files to cache on windows-latest
146+
if: matrix.os == 'windows-latest'
147+
run: |
148+
if [ ! -d ~/AppData/Local/Coursier/Cache ]; then
149+
echo "::error::The ~/AppData/Local/Coursier/Cache directory does not exist unexpectedly"
150+
exit 1
151+
fi
152+
153+
154+
- name: Check files to cache on ubuntu-latest
155+
if: matrix.os == 'ubuntu-latest'
156+
run: |
157+
if [ ! -d ~/.cache/coursier ]; then
158+
echo "::error::The ~/.cache/coursier directory does not exist unexpectedly"
159+
exit 1
160+
fi
161+
162+
sbt-restore:
163+
runs-on: ${{ matrix.os }}
164+
defaults:
165+
run:
166+
shell: bash
167+
working-directory: __tests__/cache/sbt
168+
strategy:
169+
fail-fast: false
170+
matrix:
171+
os: [macos-latest, windows-latest, ubuntu-latest]
172+
needs: sbt-save
173+
steps:
174+
- name: Checkout
175+
uses: actions/checkout@v3
176+
- name: Run setup-java with the cache for sbt
177+
uses: ./
178+
id: setup-java
179+
with:
180+
distribution: 'adopt'
181+
java-version: '11'
182+
cache: sbt
183+
184+
- name: Confirm that ~/Library/Caches/Coursier directory has been made
185+
if: matrix.os == 'macos-latest'
186+
run: |
187+
if [ ! -d ~/Library/Caches/Coursier ]; then
188+
echo "::error::The ~/Library/Caches/Coursier directory does not exist unexpectedly"
189+
exit 1
190+
fi
191+
ls ~/Library/Caches/Coursier
192+
193+
- name: Confirm that ~/AppData/Local/Coursier/Cache directory has been made
194+
if: matrix.os == 'windows-latest'
195+
run: |
196+
if [ ! -d ~/AppData/Local/Coursier/Cache ]; then
197+
echo "::error::The ~/AppData/Local/Coursier/Cache directory does not exist unexpectedly"
198+
exit 1
199+
fi
200+
ls ~/AppData/Local/Coursier/Cache
201+
202+
- name: Confirm that ~/.cache/coursier directory has been made
203+
if: matrix.os == 'ubuntu-latest'
204+
run: |
205+
if [ ! -d ~/.cache/coursier ]; then
206+
echo "::error::The ~/.cache/coursier directory does not exist unexpectedly"
207+
exit 1
208+
fi
209+
ls ~/.cache/coursier

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to make participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies within all project spaces, and it also applies when
49+
an individual is representing the project or its community in public spaces.
50+
Examples of representing a project or community include using an official
51+
project e-mail address, posting via an official social media account, or acting
52+
as an appointed representative at an online or offline event. Representation of
53+
a project may be further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at opensource+actions/setup-[email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
### NCC
1010

11-
In order to avoid uploading `node_modules` to the repository, we use [zeit/ncc](https://github.com/zeit/ncc) to create multiple `index.js` files that gets saved under `dist/`.
11+
In order to avoid uploading `node_modules` to the repository, we use [vercel/ncc](https://github.com/vercel/ncc) to create multiple `index.js` files that gets saved under `dist/`.
1212
There are two main files that get created
1313
- `dist/setup/index.js`
1414
- Core `setup-java` logic that downloads and installs an appropriate version of Java

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ Currently, the following distributions are supported:
6666
**NOTE:** Adopt OpenJDK got moved to Eclipse Temurin and won't be updated anymore. It is highly recommended to migrate workflows from `adopt` to `temurin` to keep receiving software and security updates. See more details in the [Good-bye AdoptOpenJDK post](https://blog.adoptopenjdk.net/2021/08/goodbye-adoptopenjdk-hello-adoptium/).
6767

6868
### Caching packages dependencies
69-
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under hood for caching dependencies but requires less configuration settings. Supported package managers are gradle and maven. The format of the used cache key is `setup-java-${{ platform }}-${{ packageManager }}-${{ fileHash }}`, where the hash is based on the following files:
69+
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under hood for caching dependencies but requires less configuration settings. Supported package managers are gradle, maven and sbt. The format of the used cache key is `setup-java-${{ platform }}-${{ packageManager }}-${{ fileHash }}`, where the hash is based on the following files:
7070
- gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`
7171
- maven: `**/pom.xml`
72+
- sbt: `**/build.sbt`
7273

7374
The workflow output `cache-hit` is set to indicate if an exact match was found for the key [as actions/cache does](https://github.com/actions/cache/tree/main#outputs).
7475

@@ -99,6 +100,19 @@ steps:
99100
run: mvn -B package --file pom.xml
100101
```
101102

103+
#### Caching sbt dependencies
104+
```yaml
105+
steps:
106+
- uses: actions/checkout@v3
107+
- uses: actions/setup-java@v3
108+
with:
109+
distribution: 'temurin'
110+
java-version: '11'
111+
cache: 'sbt'
112+
- name: Build with SBT
113+
run: sbt package
114+
```
115+
102116
### Check latest
103117
In the basic examples above, the `check-latest` flag defaults to `false`. When set to `false`, the action tries to first resolve a version of Java from the local tool cache on the runner. If unable to find a specific version in the cache, the action will download a version of Java. Use the default or set `check-latest` to `false` if you prefer a faster more consistent setup experience that prioritizes trying to use the cached versions at the expense of newer versions sometimes being available for download.
104118

__tests__/cache.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ describe('dependency cache', () => {
118118
expect(spyInfo).toBeCalledWith('gradle cache is not found');
119119
});
120120
});
121+
describe('for sbt', () => {
122+
it('throws error if no build.sbt found', async () => {
123+
await expect(restore('sbt')).rejects.toThrowError(
124+
`No file in ${projectRoot(
125+
workspace
126+
)} matched to [**/*.sbt,**/project/build.properties,**/project/**.{scala,sbt}], make sure you have checked out the target repository`
127+
);
128+
});
129+
it('downloads cache', async () => {
130+
createFile(join(workspace, 'build.sbt'));
131+
132+
await restore('sbt');
133+
expect(spyCacheRestore).toBeCalled();
134+
expect(spyWarning).not.toBeCalled();
135+
expect(spyInfo).toBeCalledWith('sbt cache is not found');
136+
});
137+
});
121138
});
122139
describe('save', () => {
123140
let spyCacheSave: jest.SpyInstance<
@@ -194,6 +211,30 @@ describe('dependency cache', () => {
194211
expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
195212
});
196213
});
214+
describe('for sbt', () => {
215+
it('uploads cache even if no build.sbt found', async () => {
216+
createStateForMissingBuildFile();
217+
await save('sbt');
218+
expect(spyCacheSave).toBeCalled();
219+
expect(spyWarning).not.toBeCalled();
220+
});
221+
it('does not upload cache if no restore run before', async () => {
222+
createFile(join(workspace, 'build.sbt'));
223+
224+
await save('sbt');
225+
expect(spyCacheSave).not.toBeCalled();
226+
expect(spyWarning).toBeCalledWith('Error retrieving key from state.');
227+
});
228+
it('uploads cache', async () => {
229+
createFile(join(workspace, 'build.sbt'));
230+
createStateForSuccessfulRestore();
231+
232+
await save('sbt');
233+
expect(spyCacheSave).toBeCalled();
234+
expect(spyWarning).not.toBeCalled();
235+
expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
236+
});
237+
});
197238
});
198239
});
199240

__tests__/cache/sbt/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/

__tests__/cache/sbt/build.sbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ThisBuild / scalaVersion := "2.12.15"
2+
3+
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.6.2

0 commit comments

Comments
 (0)