Skip to content

Commit c2861d8

Browse files
committed
Separate env var workflows
1 parent 621b810 commit c2861d8

File tree

6 files changed

+213
-189
lines changed

6 files changed

+213
-189
lines changed

.github/workflows/env_var.yml

Lines changed: 0 additions & 166 deletions
This file was deleted.

.github/workflows/env_var_pass.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Env Var Pass
2+
3+
on:
4+
push:
5+
schedule:
6+
- cron: "0 0 1 * *" # Midnight every month (UTC)
7+
workflow_dispatch:
8+
9+
jobs:
10+
job1:
11+
name: Example 1
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Set environment variable (takes effect in subsequent steps)
16+
run: |
17+
echo "FOO=abc" >> "${GITHUB_ENV}"
18+
echo "BAR=123" >> "${GITHUB_ENV}"
19+
echo "No effect in the current step."
20+
echo "FOO is '${FOO}'"
21+
echo "BAR is '${BAR}'"
22+
23+
- name: Show values
24+
run: |
25+
echo "FOO is '${FOO}'"
26+
echo "BAR is '${BAR}'"
27+
28+
job2:
29+
name: Example 2
30+
runs-on: ubuntu-latest
31+
outputs:
32+
GREETING: "${{ steps.pass.outputs.GREETING }}"
33+
RESPONSE: "${{ steps.pass.outputs.RESPONSE }}"
34+
35+
steps:
36+
- name: FOO and BAR are in another scope and therefore undefined
37+
run: |
38+
echo "FOO is '${FOO}'"
39+
echo "BAR is '${BAR}'"
40+
41+
- name: Set output parameters to pass values to another job
42+
id: pass
43+
run: |
44+
# single-line output
45+
echo "GREETING=Hello, World!" >> "${GITHUB_OUTPUT}"
46+
47+
# multi-line output
48+
{
49+
echo 'RESPONSE<<EOF'
50+
curl https://example.com
51+
echo EOF
52+
} >> "${GITHUB_OUTPUT}"
53+
54+
job3:
55+
name: Example 3
56+
runs-on: ubuntu-latest
57+
needs: job2
58+
59+
steps:
60+
- name: Show GREETING
61+
run: echo "GREETING is '${{ needs.job2.outputs.GREETING }}'"
62+
63+
- name: Show RESPONSE
64+
run: echo "RESPONSE is '${{ needs.job2.outputs.RESPONSE }}'"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: System PATH
1+
name: Env Var PATH
22

33
on:
44
push:
@@ -7,7 +7,7 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
one:
10+
job1:
1111
name: Example 1
1212
runs-on: ubuntu-latest
1313

@@ -24,7 +24,7 @@ jobs:
2424
- name: Show updated PATH
2525
run: echo "PATH is '${PATH}'"
2626

27-
two:
27+
job2:
2828
name: Example 2
2929
runs-on: ubuntu-latest
3030

.github/workflows/env_var_read.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Env Var Read
2+
3+
on:
4+
push:
5+
schedule:
6+
- cron: "0 0 1 * *" # Midnight every month (UTC)
7+
workflow_dispatch:
8+
9+
env:
10+
JAN: "January"
11+
FEB: "February"
12+
MAR: "March"
13+
14+
jobs:
15+
job1:
16+
name: Example 1
17+
runs-on: ubuntu-latest
18+
env:
19+
RED: "FF0000"
20+
GREEN: "00FF00"
21+
BLUE: "0000FF"
22+
23+
steps:
24+
- name: Show months, colors, and numbers
25+
run: |
26+
echo "JAN is '${JAN}'"
27+
echo "FEB is '${FEB}'"
28+
echo "MAR is '${MAR}'"
29+
echo
30+
echo "RED is '${RED}'"
31+
echo "GREEN is '${GREEN}'"
32+
echo "BLUE is '${BLUE}'"
33+
echo
34+
echo "ONE is '${ONE}'"
35+
echo "TWO is '${TWO}'"
36+
echo "THREE is '${THREE}'"
37+
env:
38+
ONE: "1"
39+
TWO: "2"
40+
THREE: "3"
41+
42+
- name: Show months and colors (numbers are in another scope and therefore undefined)
43+
run: |
44+
echo "JAN is '${JAN}'"
45+
echo "FEB is '${FEB}'"
46+
echo "MAR is '${MAR}'"
47+
echo
48+
echo "RED is '${RED}'"
49+
echo "GREEN is '${GREEN}'"
50+
echo "BLUE is '${BLUE}'"
51+
echo
52+
echo "ONE is '${ONE}'"
53+
echo "TWO is '${TWO}'"
54+
echo "THREE is '${THREE}'"
55+
56+
job2:
57+
name: Example 2
58+
runs-on: ubuntu-latest
59+
60+
steps:
61+
- name: Show months (colors and numbers are in another scope and therefore undefined)
62+
run: |
63+
echo "JAN is '${JAN}'"
64+
echo "FEB is '${FEB}'"
65+
echo "MAR is '${MAR}'"
66+
echo
67+
echo "RED is '${RED}'"
68+
echo "GREEN is '${GREEN}'"
69+
echo "BLUE is '${BLUE}'"
70+
echo
71+
echo "ONE is '${ONE}'"
72+
echo "TWO is '${TWO}'"
73+
echo "THREE is '${THREE}'"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Env Var Write
2+
3+
on:
4+
push:
5+
schedule:
6+
- cron: "0 0 1 * *" # Midnight every month (UTC)
7+
workflow_dispatch:
8+
9+
env:
10+
JAN: "January"
11+
FEB: "February"
12+
MAR: "March"
13+
14+
jobs:
15+
job1:
16+
name: Example 1
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Show months
21+
run: |
22+
echo "JAN is '${JAN}'"
23+
echo "FEB is '${FEB}'"
24+
echo "MAR is '${MAR}'"
25+
26+
- name: Overwrite months (takes effect in subsequent steps)
27+
run: |
28+
echo "JAN=01" >> "${GITHUB_ENV}"
29+
echo "FEB=02" >> "${GITHUB_ENV}"
30+
echo "MAR=03" >> "${GITHUB_ENV}"
31+
echo "No effect in the current step."
32+
echo "JAN is '${JAN}'"
33+
echo "FEB is '${FEB}'"
34+
echo "MAR is '${MAR}'"
35+
36+
- name: New months (takes effect in subsequent steps)
37+
run: |
38+
echo "APR=04" >> "${GITHUB_ENV}"
39+
echo "MAY=05" >> "${GITHUB_ENV}"
40+
echo "JUN=06" >> "${GITHUB_ENV}"
41+
echo "No effect in the current step."
42+
echo "APR is '${APR}'"
43+
echo "MAY is '${MAY}'"
44+
echo "JUN is '${JUN}'"
45+
46+
- name: Show updated months
47+
run: |
48+
echo "JAN is '${JAN}'"
49+
echo "FEB is '${FEB}'"
50+
echo "MAR is '${MAR}'"
51+
echo "APR is '${APR}'"
52+
echo "MAY is '${MAY}'"
53+
echo "JUN is '${JUN}'"
54+
55+
job2:
56+
name: Example 2
57+
runs-on: ubuntu-latest
58+
59+
steps:
60+
- name: Changes made in other jobs are isolated
61+
run: |
62+
echo "JAN is '${JAN}'"
63+
echo "FEB is '${FEB}'"
64+
echo "MAR is '${MAR}'"
65+
echo "APR is '${APR}'"
66+
echo "MAY is '${MAY}'"
67+
echo "JUN is '${JUN}'"

0 commit comments

Comments
 (0)