Skip to content

Commit b171803

Browse files
authored
Merge pull request #124 from salesforcecli/ew/input-envs
Refactor GHAs
2 parents aedf7b7 + 01209f2 commit b171803

28 files changed

Lines changed: 381 additions & 222 deletions

.github/actions/ctcOpen/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ runs:
2424
using: composite
2525
steps:
2626
- uses: actions/checkout@v4
27-
with:
28-
token: ${{ inputs.SVC_CLI_BOT_GITHUB_TOKEN }}
2927

3028
- uses: actions/setup-node@v4
3129
with:
@@ -59,5 +57,7 @@ runs:
5957
SF_CHANGE_CASE_TEMPLATE_ID: ${{ inputs.SF_CHANGE_CASE_TEMPLATE_ID}}
6058
SF_CHANGE_CASE_CONFIGURATION_ITEM: ${{ inputs.SF_CHANGE_CASE_CONFIGURATION_ITEM}}
6159

62-
- run: echo "case id is ${{ steps.ctc.outputs.ctcId }}"
60+
- run: echo "[INFO] Change Case ID is:\ $STEPS_CTC_CTCID"
6361
shell: bash
62+
env:
63+
STEPS_CTC_CTCID: ${{ steps.ctc.outputs.ctcId }}

.github/actions/determineNodeVersions/action.yml

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ outputs:
1414
description: Node versions to be consumed by a workflow matrix
1515
value: ${{ steps.node-versions.outputs.nodeVersions }}
1616

17+
# Sample output looks like this:
18+
#
19+
# nodeVersions<<EOF
20+
# [
21+
# "current",
22+
# "lts/*",
23+
# "lts/-1",
24+
# ]
25+
# EOF
26+
#
27+
# OR...
28+
#
29+
# nodeVersions<<EOF
30+
# [
31+
# "18.15.0",
32+
# "16"
33+
# ]
34+
# EOF
35+
1736
runs:
1837
using: composite
1938
steps:
@@ -24,11 +43,11 @@ runs:
2443
# Current can be disabled by setting the "nodeDisableCurrent" input to "true"
2544
# IF "NODE_VERSION" is overridden, "NODE_VERSION_CURRENT" will also be disabled
2645
NODE_VERSION_CURRENT="current"
27-
NODE_VERSION="${{ inputs.nodeVersionOverride || 'lts/*' }}"
46+
NODE_VERSION="${INPUTS_NODE_VERSION_OVERRIDE:-'lts/*'}"
2847
NODE_PREVIOUS_LTS="lts/-1"
2948
30-
if [ -n "${{ inputs.nodeVersionOverride }}" ]; then
31-
NODE_VERSION_MAJOR=$(echo "${{ inputs.nodeVersionOverride }}" | cut -d '.' -f 1)
49+
if [ -n "$INPUTS_NODE_VERSION_OVERRIDE" ]; then
50+
NODE_VERSION_MAJOR=$(echo "$INPUTS_NODE_VERSION_OVERRIDE" | cut -d '.' -f 1)
3251
3352
# LTS-1 will always be the previous LTS, which is always even. Here we calculate the nearest LTS
3453
if [ $((NODE_VERSION_MAJOR % 2)) == 0 ]; then
@@ -40,29 +59,13 @@ runs:
4059
4160
{
4261
echo "nodeVersions<<EOF"
43-
if [ "$NODE_VERSION" = "lts/*" ] && [ "${{ inputs.nodeDisableCurrent }}" != "true" ]; then
62+
if [ "$NODE_VERSION" = "lts/*" ] && [ "$INPUTS_NODE_DISABLE_CURRENT" != "true" ]; then
4463
jq -n --arg v1 "$NODE_VERSION_CURRENT" --arg v2 "$NODE_VERSION" --arg v3 "$NODE_PREVIOUS_LTS" '[$v1, $v2, $v3]'
4564
else
4665
jq -n --arg v1 "$NODE_VERSION" --arg v2 "$NODE_PREVIOUS_LTS" '[$v1, $v2]'
4766
fi
4867
echo "EOF"
4968
} >> "$GITHUB_OUTPUT"
50-
51-
# Sample output looks like this:
52-
#
53-
# nodeVersions<<EOF
54-
# [
55-
# "current",
56-
# "lts/*",
57-
# "lts/-1",
58-
# ]
59-
# EOF
60-
#
61-
# OR...
62-
#
63-
# nodeVersions<<EOF
64-
# [
65-
# "18.15.0",
66-
# "16"
67-
# ]
68-
# EOF
69+
env:
70+
INPUTS_NODE_VERSION_OVERRIDE: ${{ inputs.nodeVersionOverride }}
71+
INPUTS_NODE_DISABLE_CURRENT: ${{ inputs.nodeDisableCurrent }}

.github/actions/generateOclifReadme/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ runs:
4646
yarn tsc
4747
yarn oclif readme \
4848
--no-aliases \
49-
--version ${{ steps.next-version.outputs.tag }} \
49+
--version "$STEPS_NEXT_VERSION_TAG" \
5050
${{ inputs.multi == 'true' && '--multi' || '' }} \
5151
--repository-prefix "<%- repo %>/blob/<%- version %>/<%- commandPath %>" \
5252
|| echo "::warning::'oclif readme' failed. Check the logs."
53+
env:
54+
STEPS_NEXT_VERSION_TAG: ${{ steps.next-version.outputs.tag }}
Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,51 @@
11
name: get-json-property
2-
description: Get a property from a json file using jq
2+
description: Get a property from a json file with dot notation
33

44
# Examples:
55
# prop_path: version
6-
# prop_path: devDependencies["@salesforce/dev-scripts"]
7-
# ^ Note: double quotes needed here
6+
# prop_path: devDependencies.@salesforce/dev-scripts
87

98
inputs:
109
path:
1110
required: true
1211
description: Json file to look up prop (package.json)
1312
prop_path:
1413
required: true
15-
description: jq query to search (version)
14+
description: dot notation property to find (version)
1615

1716
outputs:
1817
prop:
1918
description: The value of the prop_path
20-
value: ${{ steps.jq.outputs.prop }}
19+
value: ${{ steps.parse.outputs.prop }}
2120

2221
runs:
2322
using: "composite"
2423
steps:
2524
- name: Get property from json file
26-
id: jq
27-
shell: bash
28-
run: |
29-
PROP=$(jq -r '.${{ inputs.prop_path }}' ${{ inputs.path }})
30-
echo "prop=$PROP" >> "$GITHUB_OUTPUT"
31-
- name: Exit if prop was not found
32-
if: ${{ steps.jq.outputs.prop == 'null' }}
25+
id: parse
3326
uses: actions/github-script@v7
3427
with:
35-
script: core.setFailed("Property '${{ inputs.prop_path }}' not found in ${{ inputs.path }}")
28+
result-encoding: string
29+
script: |
30+
try {
31+
const fs = require('fs')
32+
33+
var path = process.env.INPUTS_PATH;
34+
var propPath = process.env.INPUTS_PROP_PATH;
35+
36+
const json = JSON.parse(fs.readFileSync(path))
37+
38+
// https://stackoverflow.com/a/43849204
39+
const result = propPath.split('.').reduce((p,c)=>p&&p[c]||null, json)
40+
41+
if (result) {
42+
core.setOutput('prop', result)
43+
} else {
44+
core.setFailed(`Property '${propPath}' not found in '${path}'`)
45+
}
46+
} catch(err) {
47+
core.setFailed(err)
48+
}
49+
env:
50+
INPUTS_PATH: ${{ inputs.path }}
51+
INPUTS_PROP_PATH: ${{ inputs.prop_path }}

.github/actions/getGithubUserInfo/action.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ runs:
2222
uses: actions/github-script@v7
2323
with:
2424
script: core.setFailed("You must pass a Github Token with repo write access as SVC_CLI_BOT_GITHUB_TOKEN")
25+
2526
- name: Get Github user info
2627
id: user-info
2728
shell: bash
28-
env:
29-
GH_TOKEN: ${{ inputs.SVC_CLI_BOT_GITHUB_TOKEN }}
3029
run: |
3130
USER_INFO=$(gh api user)
3231
@@ -44,3 +43,5 @@ runs:
4443
fi
4544
4645
echo "email=$EMAIL" >> "$GITHUB_OUTPUT"
46+
env:
47+
GH_TOKEN: ${{ inputs.SVC_CLI_BOT_GITHUB_TOKEN }}

.github/actions/getPreReleaseTag/action.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,32 @@ outputs:
66
value: ${{ steps.parsed.outputs.prerelease }}
77
description: version suffix (ex 'beta' if x.y.z-beta.0 ), if exists in package.json
88
version:
9-
value: ${{ steps.packageVersion.outputs.prop }}
9+
value: ${{ steps.package-version.outputs.prop }}
1010
description: version from pjson
1111

1212
runs:
1313
using: composite
1414
steps:
1515
- uses: salesforcecli/github-workflows/.github/actions/get-json-property@main
16-
id: packageVersion
16+
id: package-version
1717
with:
1818
path: "package.json"
1919
prop_path: "version"
2020

21-
- run: echo "found version ${{ steps.packageVersion.outputs.prop }}"
21+
- name: Echo found version
2222
shell: bash
23+
run: echo "[INFO] Version found:\ $STEPS_PACKAGE_VERSION_PROP"
24+
env:
25+
STEPS_PACKAGE_VERSION_PROP: ${{ steps.package-version.outputs.prop }}
2326

24-
- uses: salesforcecli/github-workflows/.github/actions/parse-semver@main
27+
- name: Parse semver version
28+
uses: salesforcecli/github-workflows/.github/actions/parse-semver@main
2529
id: parsed
2630
with:
27-
input_string: ${{ steps.packageVersion.outputs.prop }}
31+
input_string: ${{ steps.package-version.outputs.prop }}
2832

29-
- run: echo "Prerelease tag parsing found '${{ steps.parsed.outputs.prerelease }}'"
33+
- name: Echo found prerelease tag
3034
shell: bash
35+
run: echo "[INFO] Prerelease tag is:\ $STEPS_PARSED_PRERELEASE"
36+
env:
37+
STEPS_PARSED_PRERELEASE: ${{ steps.parsed.outputs.prerelease }}

.github/actions/gitConfig/action.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ inputs:
1212
runs:
1313
using: composite
1414
steps:
15-
- run: git config --global push.default current
16-
shell: bash
17-
- run: git config --global user.name ${{ inputs.username }}
18-
shell: bash
19-
- run: git config --global user.email ${{ inputs.email }}
15+
- name: Set git config
2016
shell: bash
17+
run: |
18+
git config --global push.default current
19+
git config --global user.name "$INPUTS_USERNAME"
20+
git config --global user.email "$INPUTS_EMAIL"
21+
env:
22+
INPUTS_USERNAME: ${{ inputs.username }}
23+
INPUTS_EMAIL: ${{ inputs.email }}

.github/actions/parse-semver/action.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ runs:
3131
id: parse
3232
shell: bash
3333
run: |
34-
FULL_VERSION="${{ inputs.input_string }}"
34+
FULL_VERSION="$INPUTS_INPUT_STRING"
3535
VERSION="${FULL_VERSION#v}"
3636
3737
# Filter out non-semver characters
@@ -57,8 +57,20 @@ runs:
5757
echo "patch=$PATCH" >> "$GITHUB_OUTPUT"
5858
echo "prerelease=$PRERELEASE" >> "$GITHUB_OUTPUT"
5959
echo "fullversion=$FULL_VERSION" >> "$GITHUB_OUTPUT"
60+
env:
61+
INPUTS_INPUT_STRING: ${{ inputs.input_string }}
62+
6063
- name: Exit if major, minor, or patch not found
6164
if: ${{ !steps.parse.outputs.major || !steps.parse.outputs.minor || !steps.parse.outputs.patch }}
6265
uses: actions/github-script@v7
6366
with:
64-
script: core.setFailed("Error parsing semver ${{ inputs.input_string }}\nMajor:${{ steps.parse.outputs.major }}\nMinor:${{ steps.parse.outputs.minor }}\nPatch:${{ steps.parse.outputs.patch }}")
67+
script: |
68+
core.setFailed(`Error parsing semver: ${process.env.INPUTS_INPUT_STRING}
69+
Major: ${process.env.STEPS_PARSE_MAJOR}
70+
Minor: ${process.env.STEPS_PARSE_MINOR}
71+
Patch: ${process.env.STEPS_PARSE_PATCH}`)
72+
env:
73+
INPUTS_INPUT_STRING: ${{ inputs.input_string }}
74+
STEPS_PARSE_MAJOR: ${{ steps.parse.outputs.major }}
75+
STEPS_PARSE_MINOR: ${{ steps.parse.outputs.minor }}
76+
STEPS_PARSE_PATCH: ${{ steps.parse.outputs.patch }}

.github/actions/renameMacPkg/action.yml

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

.github/actions/versionInfo/action.yml

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,42 @@ runs:
2626
steps:
2727
- id: getSha
2828
shell: bash
29-
run: echo "sha=$(npm view ${{ inputs.npmPackage }}@${{ inputs.version }} --json | jq -r '.gitHead[0:7]')" >> "$GITHUB_OUTPUT"
29+
run: echo "sha=$(npm view $INPUTS_NPM_PACKAGE@$INPUTS_VERSION --json | jq -r '.gitHead[0:7]')" >> "$GITHUB_OUTPUT"
30+
env:
31+
INPUTS_NPM_PACKAGE: ${{ inputs.npmPackage }}
32+
INPUTS_VERSION: ${{ inputs.version }}
3033

3134
- id: getNumericalVersion
3235
shell: bash
33-
run: echo "version=$(npm view ${{ inputs.npmPackage }}@${{ inputs.version }} --json | jq -r '.version')" >> "$GITHUB_OUTPUT"
36+
run: echo "version=$(npm view $INPUTS_NPM_PACKAGE@$INPUTS_VERSION --json | jq -r '.version')" >> "$GITHUB_OUTPUT"
37+
env:
38+
INPUTS_NPM_PACKAGE: ${{ inputs.npmPackage }}
39+
INPUTS_VERSION: ${{ inputs.version }}
3440

3541
- id: getCli
3642
shell: bash
37-
run: echo "cli=$(npm view ${{ inputs.npmPackage }}@${{ inputs.version }} --json | jq -r '.oclif.bin')" >> "$GITHUB_OUTPUT"
43+
run: echo "cli=$(npm view $INPUTS_NPM_PACKAGE@$INPUTS_VERSION --json | jq -r '.oclif.bin')" >> "$GITHUB_OUTPUT"
44+
env:
45+
INPUTS_NPM_PACKAGE: ${{ inputs.npmPackage }}
46+
INPUTS_VERSION: ${{ inputs.version }}
3847

3948
- id: getS3Folder
4049
shell: bash
41-
run: echo "folder=$(npm view ${{ inputs.npmPackage }}@${{ inputs.version }} --json | jq -r '.oclif.update.s3.folder')" >> "$GITHUB_OUTPUT"
50+
run: echo "folder=$(npm view $INPUTS_NPM_PACKAGE@$INPUTS_VERSION --json | jq -r '.oclif.update.s3.folder')" >> "$GITHUB_OUTPUT"
51+
env:
52+
INPUTS_NPM_PACKAGE: ${{ inputs.npmPackage }}
53+
INPUTS_VERSION: ${{ inputs.version }}
4254

43-
- run: echo "regex found version ${{ steps.getNumericalVersion.outputs.version }} with sha ${{ steps.getSha.outputs.sha }} for cli ${{ steps.getCli.outputs.cli }}"
44-
shell: bash
45-
46-
- run: echo "xz url is https://developer.salesforce.com/${{ steps.getS3Folder.outputs.folder }}/versions/${{ steps.getNumericalVersion.outputs.version }}/${{ steps.getSha.outputs.sha }}/${{ steps.getCli.outputs.cli }}-v${{ steps.getNumericalVersion.outputs.version }}-${{ steps.getSha.outputs.sha }}-linux-x64.tar.xz"
55+
- name: Echo info
4756
shell: bash
57+
run: |
58+
echo "[INFO] version-info outputs:"
59+
echo "cli: $STEPS_GETCLI_CLI"
60+
echo "version: $STEPS_GETNUMERICALVERSION_VERSION"
61+
echo "sha: $STEPS_GETSHA_SHA"
62+
echo "folder (xz): https://developer.salesforce.com/$STEPS_GETS3FOLDER_FOLDER/versions/$STEPS_GETNUMERICALVERSION_VERSION/$STEPS_GETSHA_SHA/$STEPS_GETCLI_CLI-v$STEPS_GETNUMERICALVERSION_VERSION-$STEPS_GETSHA_SHA-linux-x64.tar.xz"
63+
env:
64+
STEPS_GETCLI_CLI: ${{ steps.getCli.outputs.cli }}
65+
STEPS_GETNUMERICALVERSION_VERSION: ${{ steps.getNumericalVersion.outputs.version }}
66+
STEPS_GETSHA_SHA: ${{ steps.getSha.outputs.sha }}
67+
STEPS_GETS3FOLDER_FOLDER: ${{ steps.getS3Folder.outputs.folder }}

0 commit comments

Comments
 (0)