Skip to content

Commit 7ae15e9

Browse files
authored
Merge pull request #29 from Seasawher/develop
add latest_lean to output
2 parents 021fbfd + e4e1b03 commit 7ae15e9

File tree

3 files changed

+71
-8
lines changed

3 files changed

+71
-8
lines changed

.github/workflows/test.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,26 @@ jobs:
3939

4040
- name: This update should fail
4141
if: steps.update.outputs.result != 'update-fail'
42-
run: exit 1
42+
run: exit 1
43+
44+
output_test:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v4
49+
50+
- name: Update Lean package
51+
id: update
52+
uses: Seasawher/lean-update@develop
53+
with:
54+
on_update_succeeds: "silent"
55+
lake_package_directory: "./test/Foo"
56+
57+
- name: output assertion of latest_lean
58+
run: |
59+
echo "Latest Lean version: ${{ steps.update.outputs.latest_lean }}"
60+
if [[ ! "${{ steps.update.outputs.latest_lean }}" =~ ^v ]]; then
61+
echo "Error: The latest_lean output should start with 'v'"
62+
exit 1
63+
fi
64+
echo "latest_lean output test passed"

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,21 @@ A Github token to be used for committing and creating issues/PRs.
161161

162162
Default: `${{ github.token }}`
163163

164+
## Outputs
165+
166+
### `result`
167+
168+
The action outputs `no-update`, `update-success` or `update-fail` depending on the three possible scenarios.
169+
170+
Description of each value:
171+
* `no-update`: No update was available.
172+
* `update-success`: An update was available and lean-action step was successful.
173+
* `update-fail`: An update was available but the lean-action step failed.
174+
175+
### `latest_lean`
176+
177+
The latest Lean release version, including both stable and pre-release versions.
178+
164179
## Usage Examples
165180

166181
I am using this GitHub Action in the following repository. This might be helpful as a reference.

action.yml

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,38 +61,46 @@ outputs:
6161
* `no-update`: No update was available.
6262
* `update-success`: An update was available and lean-action step was successful.
6363
* `update-fail`: An update was available but the lean-action step failed.
64-
value: ${{ steps.record-outcome.outputs.outcome }}
64+
value: ${{ steps.record-result.outputs.outcome }}
65+
latest_lean:
66+
description: | # markdown
67+
The latest Lean release version, including both stable and pre-release versions.
68+
value: ${{ steps.record-latest-lean.outputs.latest_lean }}
6569
runs:
6670
using: "composite"
6771
steps:
6872
- name: Update lean-toolchain
6973
run: |
70-
cd ${{ inputs.lake_package_directory }}
74+
: Update lean-toolchain
7175
node ${{ github.action_path }}/scripts/getLatest.js
7276
env:
7377
GH_TOKEN: ${{ github.token }}
7478
shell: bash
79+
working-directory: ${{ inputs.lake_package_directory }}
7580

7681
- name: Install elan
7782
run: |
83+
: Install elan
7884
curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh -s -- -y
7985
echo "$HOME/.elan/bin" >> $GITHUB_PATH
8086
shell: bash
8187

8288
- name: Update dependencies of ${{ github.repository }}
8389
run: |
84-
cd ${{ inputs.lake_package_directory }}
90+
: Update dependencies
8591
lake update
8692
shell: bash
93+
working-directory: ${{ inputs.lake_package_directory }}
8794

8895
- name: Check if lean-toolchain or lake-manifest.json were updated
8996
id: check-update
9097
run: |
91-
cd ${{ inputs.lake_package_directory }}
98+
: Check if lean-toolchain or lake-manifest.json were updated
9299
node ${{ github.action_path }}/scripts/checkChanges.js
93100
env:
94101
UPDATE_IF_MODIFIED: ${{ inputs.update_if_modified }}
95102
shell: bash
103+
working-directory: ${{ inputs.lake_package_directory }}
96104

97105
- name: Try to build lean if something was updated
98106
if: steps.check-update.outputs.files_changed == 'true'
@@ -103,9 +111,13 @@ runs:
103111
build-args: ${{ inputs.build_args }}
104112
lake-package-directory: ${{ inputs.lake_package_directory }}
105113

106-
- name: Record outcome
107-
id: record-outcome
114+
# -------------------------------- #
115+
# record the output of this action #
116+
# -------------------------------- #
117+
- name: Record the outcome
118+
id: record-result
108119
run: | # bat
120+
: Record the outcome
109121
if [ "${{ steps.check-update.outputs.files_changed }}" == "false" ]; then
110122
echo "No update available"
111123
echo "outcome=no-update" >> $GITHUB_OUTPUT
@@ -118,6 +130,16 @@ runs:
118130
fi
119131
shell: bash
120132

133+
- name: Record the latest Lean version
134+
id: record-latest-lean
135+
run: |
136+
: Record the latest Lean version
137+
LEAN_VERSION=$(cat lean-toolchain | sed 's/leanprover\/lean4://')
138+
echo "Latest Lean release is: $LEAN_VERSION"
139+
echo "latest_lean=$LEAN_VERSION" >> $GITHUB_OUTPUT
140+
shell: bash
141+
working-directory: ${{ inputs.lake_package_directory }}
142+
121143
# ------------------------- #
122144
# when update is successful #
123145
# ------------------------- #
@@ -135,6 +157,7 @@ runs:
135157
- name: Open issue if the updated lean build was successful
136158
if: steps.build-lean.outcome == 'success' && inputs.on_update_succeeds == 'issue' && steps.check-update.outputs.do_update == 'true'
137159
run: | # bat
160+
: Open issue if the updated lean build was successful
138161
CHANGED_FILES="${{ steps.check-update.outputs.changed_files }}"
139162
BULLET_LIST=""
140163
for file in $CHANGED_FILES; do
@@ -164,6 +187,7 @@ runs:
164187
- name: Open issue if the updated lean build fails
165188
if: steps.build-lean.outcome == 'failure' && inputs.on_update_fails == 'issue'
166189
run: | # bat
190+
: Open issue if the updated lean build fails
167191
CHANGED_FILES="${{ steps.check-update.outputs.changed_files }}"
168192
BULLET_LIST=""
169193
for file in $CHANGED_FILES; do
@@ -182,7 +206,9 @@ runs:
182206

183207
- name: Action fails if the updated lean build fails
184208
if: steps.build-lean.outcome == 'failure' && inputs.on_update_fails == 'fail'
185-
run: exit 1
209+
run: |
210+
: Action fails if the updated lean build fails
211+
exit 1
186212
shell: bash
187213

188214
branding:

0 commit comments

Comments
 (0)