Have the action output a versioning element so it could be used as part of the cache restore key (#239)

4678b57 · Paulo F. Oliveira · 2024-01-12 19:46

6 files +54 -20
Message
{commit_body(@commit)}

Files changed

modified .github/workflows/action.yml
+25 −0
@@ -7,6 +7,31 @@ env:
7 7 GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
8 8
9 9 jobs:
10 + version:
11 + name: Version with commit unique id
12 + runs-on: ubuntu-latest
13 + if: github.ref == 'refs/heads/main'
14 + steps:
15 + - uses: actions/checkout@v3
16 + - name: Version it!
17 + run: |
18 + # We expect a string such as const setupBeamVersion = 'undefined' in the code
19 + SHA=$(git rev-parse --short HEAD)
20 + sed -i'.bak' \
21 + -e "s/const setupBeamVersion = '.*'/const setupBeamVersion = '${SHA}'/g" \
22 + dist/index.js
23 + # it always starts by being 'undefined'
24 + NEWVER=$(grep -oE "const setupBeamVersion = '.*'" dist/index.js | cut -d\' -f2)
25 + if [ "$NEWVER" == "undefined" ]; then
26 + exit 1
27 + else
28 + echo "Continuing... new version is ${NEWVER}"
29 + fi
30 + git config user.name "GitHub Actions"
31 + git config user.email "actions@user.noreply.github.com"
32 + git add dist/index.js
33 + git commit -m "Update setup-beam version output to ${SHA}"
34 + git push origin main
10 35 check_integrity:
11 36 name: Expected local npm actions
12 37 runs-on: ubuntu-latest
modified .github/workflows/ubuntu.yml
+4 −20
@@ -24,7 +24,7 @@ jobs:
24 24 os: 'ubuntu-latest'
25 25 version-type: 'strict'
26 26 - otp-version: '25.2'
27 elixir-version: '1.14.3'
27 + elixir-version: '1.14.2'
28 28 os: 'ubuntu-latest'
29 29 - otp-version: '25.2'
30 30 elixir-version: '1.14.3'
@@ -66,14 +66,6 @@ jobs:
66 66 otp-version: '21'
67 67 rebar3-version: '3.12'
68 68 os: 'ubuntu-20.04'
69 - elixir-version: 'v1.6'
70 otp-version: '21'
71 rebar3-version: '3.12'
72 os: 'ubuntu-20.04'
73 - elixir-version: 'v1.7'
74 otp-version: '22'
75 rebar3-version: '3.13'
76 os: 'ubuntu-20.04'
77 69 - elixir-version: 'v1.7'
78 70 otp-version: '22'
79 71 rebar3-version: '3.13'
@@ -86,18 +78,10 @@ jobs:
86 78 otp-version: '25.0.2'
87 79 rebar3-version: '3.19'
88 80 os: 'ubuntu-20.04'
89 - elixir-version: 'v1.10'
90 otp-version: '23'
91 rebar3-version: '3.14'
92 os: 'ubuntu-20.04'
93 81 - elixir-version: 'v1.12'
94 82 otp-version: '24'
95 83 rebar3-version: '3.15'
96 84 os: 'ubuntu-20.04'
97 - elixir-version: 'v1.13.4'
98 otp-version: '25.0.2'
99 rebar3-version: '3.19'
100 os: 'ubuntu-20.04'
101 85 - elixir-version: 'v1.11.0'
102 86 otp-version: '22.3.4.2'
103 87 os: 'ubuntu-20.04'
@@ -108,11 +92,11 @@ jobs:
108 92 version-type: 'strict'
109 93 - elixir-version: 'main'
110 94 otp-version: '23.1'
111 os: 'ubuntu-20.04'
95 + os: 'ubuntu-20.04'
112 96 version-type: 'strict'
113 97 - elixir-version: 'main'
114 98 otp-version: '25'
115 os: 'ubuntu-20.04'
99 + os: 'ubuntu-20.04'
116 100 version-type: 'strict'
117 101 - gleam-version: '0.23'
118 102 otp-version: '24'
@@ -126,7 +110,7 @@ jobs:
126 110 otp-version: false
127 111 os: 'ubuntu-latest'
128 112 disable_problem_matchers: true
129 - gleam-version: '0.22.0' # Version with Gleam's old archive naming convention
113 + - gleam-version: '0.22.0' # Version with Gleam's old archive naming convention
130 114 otp-version: '24'
131 115 os: 'ubuntu-latest'
132 116 disable_problem_matchers: true
modified README.md
+15 −0
@@ -88,6 +88,21 @@ jobs:
88 88 ...
89 89 ```
90 90
91 +### Outputs
92 +
93 +The action provides the following outputs:
94 +
95 +| Output | Content
96 +|- |-
97 +| otp-version | The Erlang version, e.g. `OTP-26.0`
98 +| elixir-version | The Elixir version, e.g. `v1.14-otp-26`
99 +| gleam-version | The Gleam version, e.g. `v0.23.0`
100 +| rebar3-version | The `rebar3` version, e.g. `3.18.0`
101 +| setup-beam-version | The commit unique id of the executed action version, e.g. `a34c98f`
102 +
103 +accessible as `${{steps.<setup-beam-step-id>.outputs.<Output>}}`,
104 +e.g. `${{steps.setup-beam.outputs.erlang-version}}`
105 +
91 106 ### Version file
92 107
93 108 A version file is specified via input `version-file` (e.g.`.tool-versions`). This
modified action.yml
+2 −0
@@ -58,6 +58,8 @@ outputs:
58 58 description: Exact version of Gleam that was installed
59 59 rebar3-version:
60 60 description: Exact version of rebar3 that was installed
61 + setup-beam-version:
62 + description: The commit unique id of the execution action version
61 63 runs:
62 64 using: node16
63 65 main: dist/index.js
modified dist/index.js
+4 −0
@@ -9868,6 +9868,10 @@ async function main() {
9868 9868
9869 9869 await maybeInstallGleam(gleamSpec)
9870 9870 await maybeInstallRebar3(rebar3Spec)
9871 +
9872 + // undefined is replaced by a function, post- main branch merge
9873 + const setupBeamVersion = 'undefined'
9874 + core.setOutput('setup-beam-version', setupBeamVersion)
9871 9875 }
9872 9876
9873 9877 async function installOTP(otpSpec, osVersion) {
modified src/setup-beam.js
+4 −0
@@ -47,6 +47,10 @@ async function main() {
47 47
48 48 await maybeInstallGleam(gleamSpec)
49 49 await maybeInstallRebar3(rebar3Spec)
50 +
51 + // undefined is replaced by a function, post- main branch merge
52 + const setupBeamVersion = 'undefined'
53 + core.setOutput('setup-beam-version', setupBeamVersion)
50 54 }
51 55
52 56 async function installOTP(otpSpec, osVersion) {

Parents: a34c98f