Skip to content

Commit 309bee1

Browse files
authored
Extract set-envs action (#14)
1 parent f2d47f5 commit 309bee1

File tree

2 files changed

+65
-47
lines changed

2 files changed

+65
-47
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Set Envs
2+
3+
runs:
4+
using: composite
5+
steps:
6+
- run: echo OS=Linux >> $GITHUB_ENV
7+
if: runner.os == 'Linux'
8+
shell: bash
9+
- run: echo OS=Darwin >> $GITHUB_ENV
10+
if: runner.os == 'macOS'
11+
shell: bash
12+
- run: |
13+
echo "::error title=Unable to determine OS::Unexpected runner.os '${RUNNER_OS}'"
14+
exit 1
15+
if: env.OS == ''
16+
env:
17+
RUNNER_OS: ${{ runner.os }}
18+
shell: bash
19+
20+
- run: echo ARCH=arm64 >> $GITHUB_ENV
21+
if: runner.arch == 'ARM64'
22+
shell: bash
23+
- run: echo ARCH=amd64 >> $GITHUB_ENV
24+
if: runner.arch == 'X64'
25+
shell: bash
26+
- run: |
27+
echo "::error title=Unable to determine ARCH::Unexpected runner.arch '${RUNNER_ARCH}'"
28+
exit 1
29+
if: env.ARCH == ''
30+
env:
31+
RUNNER_ARCH: ${{ runner.arch }}
32+
shell: bash

.github/workflows/ci.yml

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,36 @@ jobs:
6060
- macos-15-intel
6161
runs-on: ${{ matrix.runs-on }}
6262
steps:
63-
- name: Set OS environment variable
64-
run: echo OS="$(uname -s)" >> $GITHUB_ENV
65-
- run: echo "${OS}"
66-
67-
- name: Set ARCH environment variable
68-
run: |
69-
arch="$(uname -m)"
70-
test "${arch}" = "aarch64" && arch="arm64"
71-
test "${arch}" = "x86_64" && arch="amd64"
72-
echo ARCH="${arch}" >> $GITHUB_ENV
73-
- run: echo "$ARCH"
63+
- uses: actions/checkout@v5
64+
with:
65+
sparse-checkout: |
66+
.github/actions/set-envs
67+
craft.yml
68+
sparse-checkout-cone-mode: false
7469

75-
- name: Set SPC_OS environment variable
76-
run: |
77-
spc_os="${OS}"
78-
test "${OS}" = "Darwin" && spc_os="macos"
79-
test "${OS}" = "Linux" && spc_os="linux"
80-
echo SPC_OS="${spc_os}" >> $GITHUB_ENV
81-
- run: echo "${SPC_OS}"
70+
- uses: ./.github/actions/set-envs
8271

83-
- name: Set SPC_ARCH environment variable
84-
run: |
85-
spc_arch="${ARCH}"
86-
test "${spc_arch}" = "arm64" && spc_arch="aarch64"
87-
test "${spc_arch}" = "amd64" && spc_arch="x86_64"
88-
echo "SPC_ARCH=${spc_arch}" >> $GITHUB_ENV
89-
- run: echo "${SPC_ARCH}"
72+
- run: echo SPC_OS=linux >> $GITHUB_ENV
73+
if: runner.os == 'Linux'
74+
- run: echo SPC_OS=macos >> $GITHUB_ENV
75+
if: runner.os == 'macOS'
76+
- run: |
77+
echo "::error title=Unable to determine SPC_OS::Unexpected runner.os '${RUNNER_OS}'"
78+
exit 1
79+
if: env.SPC_OS == ''
80+
env:
81+
RUNNER_OS: ${{ runner.os }}
82+
83+
- run: echo SPC_ARCH=aarch64 >> $GITHUB_ENV
84+
if: runner.arch == 'ARM64'
85+
- run: echo SPC_ARCH=x86_64 >> $GITHUB_ENV
86+
if: runner.arch == 'X64'
87+
- run: |
88+
echo "::error title=Unable to determine SPC_ARCH::Unexpected runner.arch '${RUNNER_ARCH}'"
89+
exit 1
90+
if: env.SPC_ARCH == ''
91+
env:
92+
RUNNER_ARCH: ${{ runner.arch }}
9093
9194
- name: Install spc
9295
run: |
@@ -98,11 +101,6 @@ jobs:
98101
PATTERN: spc-${{ env.SPC_OS }}-${{ env.SPC_ARCH }}.tar.gz
99102
GH_TOKEN: ${{ github.token }}
100103

101-
- uses: actions/checkout@v5
102-
with:
103-
sparse-checkout: |
104-
craft.yml
105-
sparse-checkout-cone-mode: false
106104
- uses: actions/download-artifact@v5
107105
with:
108106
name: composer-semver.phar
@@ -197,13 +195,9 @@ jobs:
197195
env:
198196
GOFLAGS: '-mod=mod'
199197
steps:
200-
- name: Set ARCH environment variable
201-
run: |
202-
arch="$(uname -m)"
203-
test "${arch}" = "aarch64" && arch="arm64"
204-
test "${arch}" = "x86_64" && arch="amd64"
205-
echo ARCH="${arch}" >> $GITHUB_ENV
206-
- run: echo "$ARCH"
198+
- uses: actions/checkout@v5
199+
200+
- uses: ./.github/actions/set-envs
207201

208202
- uses: actions/download-artifact@v5
209203
with:
@@ -212,8 +206,6 @@ jobs:
212206

213207
- run: sudo dpkg -i "deb/composer-semver_Linux_${ARCH}.deb"
214208

215-
- uses: actions/checkout@v5
216-
217209
- uses: actions/setup-go@v6
218210
with:
219211
go-version-file: 'go.mod'
@@ -234,16 +226,10 @@ jobs:
234226
env:
235227
GOFLAGS: '-mod=mod'
236228
steps:
237-
- name: Set ARCH environment variable
238-
run: |
239-
arch="$(uname -m)"
240-
test "${arch}" = "aarch64" && arch="arm64"
241-
test "${arch}" = "x86_64" && arch="amd64"
242-
echo ARCH="${arch}" >> $GITHUB_ENV
243-
- run: echo "$ARCH"
244-
245229
- uses: actions/checkout@v5
246230

231+
- uses: ./.github/actions/set-envs
232+
247233
- uses: actions/download-artifact@v5
248234
with:
249235
name: composer-semver_Darwin_${{ env.ARCH }}

0 commit comments

Comments
 (0)