Skip to content

Commit e5759b4

Browse files
authored
Merge pull request #31 from Seasawher/develop
add notify(boolean) outputs
2 parents 605c298 + 5c2a4ce commit e5759b4

File tree

4 files changed

+58
-10
lines changed

4 files changed

+58
-10
lines changed

.github/workflows/test.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,20 @@ jobs:
5555
lake_package_directory: "./test/Foo"
5656

5757
- name: output assertion of latest_lean
58-
run: |
58+
run: | # bat
5959
echo "Latest Lean version: ${{ steps.update.outputs.latest_lean }}"
6060
if [[ ! "${{ steps.update.outputs.latest_lean }}" =~ ^v ]]; then
6161
echo "Error: The latest_lean output should start with 'v'"
6262
exit 1
6363
fi
64-
echo "latest_lean output test passed"
64+
echo "latest_lean output test passed"
65+
66+
- name: output assertion of notify
67+
run: | # bat
68+
echo "Notify status: ${{ steps.update.outputs.notify }}"
69+
if [[ "${{ steps.update.outputs.notify }}" != "true" ]]; then
70+
echo "Error: The notify output should be 'true' for this test case"
71+
echo "This test should have updates available with a successful build"
72+
exit 1
73+
fi
74+
echo "notify output test passed"

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,10 @@ Description of each value:
176176

177177
The latest Lean release version, including both stable and pre-release versions.
178178

179+
### `notify`
180+
181+
Indicates whether there is an event worth notifying the user about.
182+
Returns `true` in the following cases:
183+
* When updates are available and the build succeeds. However, if `update_if_modified` is set to `lean-toolchain`, this is only true when the Lean version has been updated.
184+
* When updates are available and the build fails.
185+
Returns `false` in all other cases.

action.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ outputs:
6666
description: | # markdown
6767
The latest Lean release version, including both stable and pre-release versions.
6868
value: ${{ steps.record-latest-lean.outputs.latest_lean }}
69+
notify:
70+
description: | # markdown
71+
Indicates whether there is an event worth notifying the user about.
72+
Returns `true` in the following cases:
73+
* When updates are available and the build succeeds. However, if `update_if_modified` is set to `lean-toolchain`, this is only true when the Lean version has been updated.
74+
* When updates are available and the build fails.
75+
Returns `false` in all other cases.
76+
value: ${{ steps.record-notify.outputs.notify }}
6977
runs:
7078
using: "composite"
7179
steps:
@@ -140,6 +148,25 @@ runs:
140148
shell: bash
141149
working-directory: ${{ inputs.lake_package_directory }}
142150

151+
- name: Record the notify status
152+
id: record-notify
153+
run: |
154+
: Record the notify status
155+
if [ "${{ steps.check-update.outputs.files_changed }}" == "false" ]; then
156+
echo "No updates available, no need to notify"
157+
echo "notify=false" >> $GITHUB_OUTPUT
158+
elif [ "${{ steps.build-lean.outcome }}" == "success" ] && [ "${{ steps.check-update.outputs.do_update }}" == "true" ]; then
159+
echo "Updates available and build successful - should notify"
160+
echo "notify=true" >> $GITHUB_OUTPUT
161+
elif [ "${{ steps.build-lean.outcome }}" == "failure" ]; then
162+
echo "Updates available but build failed - should notify"
163+
echo "notify=true" >> $GITHUB_OUTPUT
164+
else
165+
echo "No need to notify in this case"
166+
echo "notify=false" >> $GITHUB_OUTPUT
167+
fi
168+
shell: bash
169+
143170
# ------------------------- #
144171
# when update is successful #
145172
# ------------------------- #

scripts/checkChanges.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,30 @@ if (!allCandidates.includes(updateIfModified)) {
1818
process.exit(1);
1919
}
2020

21-
try {
22-
const updateIfModifiedDiff = execSync(`git diff -w ${updateIfModified}`, { encoding: 'utf8' });
23-
doUpdate = updateIfModifiedDiff.length > 0;
24-
} catch (error) {
25-
console.error(`Error checking diff for ${updateIfModified}:`, error);
26-
doUpdate = false;
27-
}
28-
2921
// Check all candidate files for changes
22+
const fileChanges = {};
3023
allCandidates.forEach(candidate => {
3124
try {
3225
const diff = execSync(`git diff -w ${candidate}`, { encoding: 'utf8' });
26+
fileChanges[candidate] = diff.length > 0;
3327
if (diff.length > 0) {
3428
changedFiles.push(candidate);
3529
}
3630
} catch (error) {
3731
console.error(`Error checking diff for ${candidate}:`, error);
32+
fileChanges[candidate] = false;
3833
}
3934
});
4035

36+
// Determine if updates should proceed based on the specified update_if_modified value
37+
if (updateIfModified === 'lean-toolchain') {
38+
// If update_if_modified is lean-toolchain, only proceed if lean-toolchain has changed
39+
doUpdate = fileChanges['lean-toolchain'];
40+
} else if (updateIfModified === 'lake-manifest.json') {
41+
// If update_if_modified is lake-manifest.json, proceed if any file has changed
42+
doUpdate = changedFiles.length > 0;
43+
}
44+
4145
// Create result object
4246
const result = {
4347
files_changed: changedFiles.length > 0,

0 commit comments

Comments
 (0)