File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010
1111For a steady stream of TILs, [ sign up for my newsletter] ( https://tinyletter.com/jbranchaud ) .
1212
13- _ 1055 TILs and counting..._
13+ _ 1056 TILs and counting..._
1414
1515---
1616
@@ -25,6 +25,7 @@ _1055 TILs and counting..._
2525* [ Elixir] ( #elixir )
2626* [ Gatsby] ( #gatsby )
2727* [ Git] ( #git )
28+ * [ GitHub Actions] ( #github-actions )
2829* [ Go] ( #go )
2930* [ HTML] ( #html )
3031* [ HTTP] ( #http )
@@ -298,6 +299,10 @@ _1055 TILs and counting..._
298299- [ What Is The Current Branch?] ( git/what-is-the-current-branch.md )
299300- [ Whitespace Warnings] ( git/whitespace-warnings.md )
300301
302+ ### GitHub Actions
303+
304+ - [ Capture An Output Value For Use In A Later Step] ( github-actions/capture-an-output-value-for-use-in-a-later-step.md )
305+
301306### Go
302307
303308- [ Access Go Docs Offline] ( go/access-go-docs-offline.md )
Original file line number Diff line number Diff line change 1+ # Capture An Output Value For Use In A Later Step
2+
3+ GitHub Actions has a workflow command called ` set-output ` . This can be used to
4+ capture the output from a shell command in step. That output value can then be
5+ used in a later step.
6+
7+ A useful example of this is reading the version of a tool from a dot-file to
8+ tell a later step what version of that tool to install.
9+
10+ Here's the ` .tool-versions ` file included in my repository:
11+
12+ ```
13+ postgres 13.1
14+ ruby 3.0.0
15+ nodejs 15.4.0
16+ ```
17+
18+ Assuming I've already [ checked out my
19+ repo] ( https://github.com/actions/checkout ) , I can find and read the ` nodejs `
20+ version from my ` .tool-versions ` file with a step that uses ` set-output ` .
21+
22+ ``` yaml
23+ - name : Read Node.js version to install from `.tool-versions`
24+ id : nodejs
25+ run : >-
26+ echo "::set-output name=NODE_VERSION::$(
27+ cat .tool-versions |
28+ grep nodejs |
29+ sed 's/nodejs \(.*\)$/\1/'
30+ )"
31+ ` ` `
32+
33+ ` echo` runs the command in the string which sets `NODE_VERSION` as an output
34+ value to what ends up being `15.4.0`.
35+
36+ This output value can be referenced in a later step.
37+
38+ ` ` ` yaml
39+ - name: Install required Node.js version
40+ uses: actions/setup-node@v1
41+ with:
42+ node-version: "${{ steps.nodejs.outputs.NODE_VERSION }}"
43+ ` ` `
44+
45+ ` steps` has a reference to the `nodejs` step (note the `id` above) which then
46+ has `outputs` like the `NODE_VERSION`.
47+
48+ [source](https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#using-workflow-commands-to-access-toolkit-functions)
You can’t perform that action at this time.
0 commit comments