-
Notifications
You must be signed in to change notification settings - Fork 7
201 lines (188 loc) · 7.13 KB
/
cmd.yml
File metadata and controls
201 lines (188 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Command with a default JVM, coursier caching and an optional matrix
on:
workflow_call:
inputs:
ref:
type: string
required: false
default: ''
java:
type: string
required: false
default: "17"
java-index:
type: string
required: false
default: ''
scala:
type: string
required: false
default: ""
add-dimensions:
type: string
required: false
default: "{}"
include:
type: string
required: false
default: "[]"
exclude:
type: string
required: false
default: "[]"
cmd:
type: string
required: true
env:
type: string
required: false
default: ""
cache-key:
type: string
required: false
default: ""
cache-path:
type: string
required: false
default: ""
ignore-job-coursier-cache:
type: boolean
required: false
default: true
ignore-matrix-coursier-cache:
type: boolean
required: false
default: true
extra-coursier-cache-key:
type: string
required: false
default: ''
run-scheduled-in-forks:
type: boolean
required: false
default: false
gradle-build-root:
type: string
required: false
default: ""
jobs:
prepare-matrix:
name: Prepare Matrix
if: >-
github.event.repository.fork == false ||
github.event_name != 'schedule' ||
(github.event_name == 'schedule' && github.event.repository.fork == true && inputs.run-scheduled-in-forks == true)
runs-on: ubuntu-24.04
outputs:
matrix: ${{ steps.prepare-matrix.outputs.matrix }}
steps:
- id: prepare-matrix
run: |
add_dimensions=$(echo -n '${{ inputs.add-dimensions }}' | sed 's/^.*{//;s/}.*$//') # Remove leading { and trailing }
# input java/scala | replace whitespaces/commas/quotes by newline | drop empty | quotation | join by comma
java=$(echo -n '${{inputs.java}}' | sed 's/[[:blank:],"]\+/\n/g' | awk NF | sed 's/^..*$/"&"/' | sed ':a; N; $!ba; s/\n/,/g')
scala=$(echo -n '${{inputs.scala}}' | sed 's/[[:blank:],"]\+/\n/g' | awk NF | sed 's/^..*$/"&"/' | sed ':a; N; $!ba; s/\n/,/g')
matrix="{"
matrix+="\"java\": [$java],"
[[ ! -z "$scala" ]] && matrix+="\"scala\": [$scala],"
matrix+="$(echo ${add_dimensions:+$add_dimensions,})"
matrix+="\"include\":$(echo -n '${{ inputs.include }}'),"
matrix+="\"exclude\":$(echo -n '${{ inputs.exclude }}')"
matrix+="}"
# Cleanup JSON (no unnecessary whitespaces, etc.)
matrix=$(jq -n -c "$matrix")
echo $matrix
echo "matrix=$matrix" >> $GITHUB_OUTPUT
cmd:
name: ${{ toJSON(matrix) }}
if: ${{ github.event.repository.fork == false || github.event_name != 'schedule' || (github.event_name == 'schedule' && github.event.repository.fork == true && inputs.run-scheduled-in-forks == true) }}
needs: prepare-matrix
runs-on: ubuntu-24.04
strategy:
# WA: https://github.community/t/reusable-workflow-with-strategy-matrix/205676/6
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix)}}
steps:
- name: Block deprecated repos in /etc/hosts
run: |
sudo echo "127.0.0.1 repo.scala-sbt.org" | sudo tee -a /etc/hosts
sudo echo "127.0.0.1 repo.typesafe.com" | sudo tee -a /etc/hosts
- name: Checkout
uses: actions/checkout@v6
with:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0
ref: ${{ inputs.ref }}
- name: Set ENV variables
if: inputs.env != ''
run: echo '${{ inputs.env }}' >> $GITHUB_ENV
- name: Coursier Cache
id: coursier-cache
uses: coursier/cache-action@v8
with:
ignoreJob: ${{ inputs.ignore-job-coursier-cache }}
ignoreMatrix: ${{ inputs.ignore-matrix-coursier-cache }}
extraKey: ${{ inputs.extra-coursier-cache-key }}
- name: Gradle Cache
uses: burrunan/gradle-cache-action@v3
with:
build-root-directory: ${{ inputs.gradle-build-root }}
# Disable caching of ~/.gradle/caches/build-cache-*
save-local-build-cache: false
# Disable caching of ~/.m2/repository/
save-maven-dependencies-cache: false
- name: Custom Cache
uses: actions/cache@v5
if: ${{ inputs.cache-key != '' && inputs.cache-path != '' }}
with:
key: ${{ format(inputs.cache-key, matrix.java) }}
path: ${{ inputs.cache-path }}
- name: Install Adoptium Temurin OpenJDK
uses: coursier/setup-action@v3
with:
jvm: adoptium:${{ matrix.java }}
jvm-index: ${{ inputs.java-index }}
- name: Install sbt
uses: sbt/setup-sbt@v1
- name: Print helpful configs and files and show environment
run: |
echo "Matrix: ${{ toJSON(matrix) }}"
echo "$ cat /etc/sbt/jvmopts"
cat /etc/sbt/jvmopts || true
echo ""
echo "$ cat /etc/sbt/sbtopts"
cat /etc/sbt/sbtopts || true
echo ""
echo "$ env"
env
echo "ls -alFhR ~/.ivy2 | grep play | grep jar"
ls -alFhR ~/.ivy2 | grep play | grep jar || true
echo "ls -alFhR ~/.cache/coursier | grep play | grep jar"
ls -alFhR ~/.cache/coursier | grep play | grep jar || true
- name: Convert matrix elements to environment variables
run: |
jq -n -r '$in | to_entries|map("MATRIX_\(.key|ascii_upcase)=\(.value|tostring)")|.[]' --argjson in '${{ toJSON(matrix) }}' >> $GITHUB_ENV
- name: Set Java installation used by sbt-java-formatter to run google-java-format
shell: bash
run: |
# JAVA_HOME_25_X64 is set by GitHub in all ubuntu-...[-arm] and Windows images, fallbacks are for macOS image
formatter_java_home="${JAVA_HOME_25_X64:-${JAVA_HOME_25_arm64:-$JAVA_HOME_25_aarch64}}"
[ -n "$formatter_java_home" ] || {
echo "None of JAVA_HOME_25_X64, JAVA_HOME_25_arm64, or JAVA_HOME_25_aarch64 is set"
exit 1
}
[ -x "$formatter_java_home/bin/java" ] || {
echo "No executable java found at $formatter_java_home/bin/java"
exit 1
}
echo "SBT_JAVAFMT_JAVA_HOME=$formatter_java_home" >> "$GITHUB_ENV"
- name: Run command
run: ${{ inputs.cmd }}
env:
CACHE_HIT_COURSIER: ${{ steps.coursier-cache.outputs.cache-hit-coursier }}
- name: Cleanup before cache
shell: bash
run: |
find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
find $HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.sbt -name "*.lock" -delete || true