Skip to content

Commit

Permalink
fix: refactor ghas
Browse files Browse the repository at this point in the history
  • Loading branch information
iowillhoit committed Aug 1, 2024
1 parent 3385209 commit 68b466e
Show file tree
Hide file tree
Showing 28 changed files with 378 additions and 223 deletions.
4 changes: 3 additions & 1 deletion .github/actions/ctcOpen/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ runs:
SF_CHANGE_CASE_TEMPLATE_ID: ${{ inputs.SF_CHANGE_CASE_TEMPLATE_ID}}
SF_CHANGE_CASE_CONFIGURATION_ITEM: ${{ inputs.SF_CHANGE_CASE_CONFIGURATION_ITEM}}

- run: echo "case id is ${{ steps.ctc.outputs.ctcId }}"
- run: echo "[INFO] Change Case ID is:\ $STEPS_CTC_CTCID"
shell: bash
env:
STEPS_CTC_CTCID: ${{ steps.ctc.outputs.ctcId }}
49 changes: 26 additions & 23 deletions .github/actions/determineNodeVersions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ outputs:
description: Node versions to be consumed by a workflow matrix
value: ${{ steps.node-versions.outputs.nodeVersions }}

# Sample output looks like this:
#
# nodeVersions<<EOF
# [
# "current",
# "lts/*",
# "lts/-1",
# ]
# EOF
#
# OR...
#
# nodeVersions<<EOF
# [
# "18.15.0",
# "16"
# ]
# EOF

runs:
using: composite
steps:
Expand All @@ -24,11 +43,11 @@ runs:
# Current can be disabled by setting the "nodeDisableCurrent" input to "true"
# IF "NODE_VERSION" is overridden, "NODE_VERSION_CURRENT" will also be disabled
NODE_VERSION_CURRENT="current"
NODE_VERSION="${{ inputs.nodeVersionOverride || 'lts/*' }}"
NODE_VERSION="${INPUTS_NODE_VERSION_OVERRIDE:-'lts/*'}"
NODE_PREVIOUS_LTS="lts/-1"
if [ -n "${{ inputs.nodeVersionOverride }}" ]; then
NODE_VERSION_MAJOR=$(echo "${{ inputs.nodeVersionOverride }}" | cut -d '.' -f 1)
if [ -n "$INPUTS_NODE_VERSION_OVERRIDE" ]; then
NODE_VERSION_MAJOR=$(echo "$INPUTS_NODE_VERSION_OVERRIDE" | cut -d '.' -f 1)
# LTS-1 will always be the previous LTS, which is always even. Here we calculate the nearest LTS
if [ $((NODE_VERSION_MAJOR % 2)) == 0 ]; then
Expand All @@ -40,29 +59,13 @@ runs:
{
echo "nodeVersions<<EOF"
if [ "$NODE_VERSION" = "lts/*" ] && [ "${{ inputs.nodeDisableCurrent }}" != "true" ]; then
if [ "$NODE_VERSION" = "lts/*" ] && [ "$INPUTS_NODE_DISABLE_CURRENT" != "true" ]; then
jq -n --arg v1 "$NODE_VERSION_CURRENT" --arg v2 "$NODE_VERSION" --arg v3 "$NODE_PREVIOUS_LTS" '[$v1, $v2, $v3]'
else
jq -n --arg v1 "$NODE_VERSION" --arg v2 "$NODE_PREVIOUS_LTS" '[$v1, $v2]'
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
# Sample output looks like this:
#
# nodeVersions<<EOF
# [
# "current",
# "lts/*",
# "lts/-1",
# ]
# EOF
#
# OR...
#
# nodeVersions<<EOF
# [
# "18.15.0",
# "16"
# ]
# EOF
env:
INPUTS_NODE_VERSION_OVERRIDE: ${{ inputs.nodeVersionOverride }}
INPUTS_NODE_DISABLE_CURRENT: ${{ inputs.nodeDisableCurrent }}
4 changes: 3 additions & 1 deletion .github/actions/generateOclifReadme/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ runs:
yarn tsc
yarn oclif readme \
--no-aliases \
--version ${{ steps.next-version.outputs.tag }} \
--version "$STEPS_NEXT_VERSION_TAG" \
${{ inputs.multi == 'true' && '--multi' || '' }} \
--repository-prefix "<%- repo %>/blob/<%- version %>/<%- commandPath %>" \
|| echo "::warning::'oclif readme' failed. Check the logs."
env:
STEPS_NEXT_VERSION_TAG: ${{ steps.next-version.outputs.tag }}
42 changes: 29 additions & 13 deletions .github/actions/get-json-property/action.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
name: get-json-property
description: Get a property from a json file using jq
description: Get a property from a json file with dot notation

# Examples:
# prop_path: version
# prop_path: devDependencies["@salesforce/dev-scripts"]
# ^ Note: double quotes needed here
# prop_path: devDependencies.@salesforce/dev-scripts

inputs:
path:
required: true
description: Json file to look up prop (package.json)
prop_path:
required: true
description: jq query to search (version)
description: dot notation property to find (version)

outputs:
prop:
description: The value of the prop_path
value: ${{ steps.jq.outputs.prop }}
value: ${{ steps.parse.outputs.prop }}

runs:
using: "composite"
steps:
- name: Get property from json file
id: jq
shell: bash
run: |
PROP=$(jq -r '.${{ inputs.prop_path }}' ${{ inputs.path }})
echo "prop=$PROP" >> "$GITHUB_OUTPUT"
- name: Exit if prop was not found
if: ${{ steps.jq.outputs.prop == 'null' }}
id: parse
uses: actions/github-script@v7
with:
script: core.setFailed("Property '${{ inputs.prop_path }}' not found in ${{ inputs.path }}")
result-encoding: string
script: |
try {
const fs = require('fs')
var path = process.env.INPUTS_PATH;
var propPath = process.env.INPUTS_PROP_PATH;
const json = JSON.parse(fs.readFileSync(path))
// https://stackoverflow.com/a/43849204
const result = propPath.split('.').reduce((p,c)=>p&&p[c]||null, json)
if (result) {
core.setOutput('prop', result)
} else {
core.setFailed(`Property '${propPath}' not found in '${path}'`)
}
} catch(err) {
core.setFailed(err)
}
env:
INPUTS_PATH: ${{ inputs.path }}
INPUTS_PROP_PATH: ${{ inputs.prop_path }}
5 changes: 3 additions & 2 deletions .github/actions/getGithubUserInfo/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ runs:
uses: actions/github-script@v7
with:
script: core.setFailed("You must pass a Github Token with repo write access as SVC_CLI_BOT_GITHUB_TOKEN")

- name: Get Github user info
id: user-info
shell: bash
env:
GH_TOKEN: ${{ inputs.SVC_CLI_BOT_GITHUB_TOKEN }}
run: |
USER_INFO=$(gh api user)
Expand All @@ -44,3 +43,5 @@ runs:
fi
echo "email=$EMAIL" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ inputs.SVC_CLI_BOT_GITHUB_TOKEN }}
19 changes: 13 additions & 6 deletions .github/actions/getPreReleaseTag/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@ outputs:
value: ${{ steps.parsed.outputs.prerelease }}
description: version suffix (ex 'beta' if x.y.z-beta.0 ), if exists in package.json
version:
value: ${{ steps.packageVersion.outputs.prop }}
value: ${{ steps.package-version.outputs.prop }}
description: version from pjson

runs:
using: composite
steps:
- uses: salesforcecli/github-workflows/.github/actions/get-json-property@main
id: packageVersion
id: package-version
with:
path: "package.json"
prop_path: "version"

- run: echo "found version ${{ steps.packageVersion.outputs.prop }}"
- name: Echo found version
shell: bash
run: echo "[INFO] Version found:\ $STEPS_PACKAGE_VERSION_PROP"
env:
STEPS_PACKAGE_VERSION_PROP: ${{ steps.package-version.outputs.prop }}

- uses: salesforcecli/github-workflows/.github/actions/parse-semver@main
- name: Parse semver version
uses: salesforcecli/github-workflows/.github/actions/parse-semver@main
id: parsed
with:
input_string: ${{ steps.packageVersion.outputs.prop }}
input_string: ${{ steps.package-version.outputs.prop }}

- run: echo "Prerelease tag parsing found '${{ steps.parsed.outputs.prerelease }}'"
- name: Echo found prerelease tag
shell: bash
run: echo "[INFO] Prerelease tag is:\ $STEPS_PARSED_PRERELEASE"
env:
STEPS_PARSED_PRERELEASE: ${{ steps.parsed.outputs.prerelease }}
13 changes: 8 additions & 5 deletions .github/actions/gitConfig/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ inputs:
runs:
using: composite
steps:
- run: git config --global push.default current
shell: bash
- run: git config --global user.name ${{ inputs.username }}
shell: bash
- run: git config --global user.email ${{ inputs.email }}
- name: Set git config
shell: bash
run: |
git config --global push.default current
git config --global user.name "$INPUTS_USERNAME"
git config --global user.email "INPUTS_EMAIL"
env:
INPUTS_USERNAME: ${{ inputs.username }}
INPUTS_EMAIL: ${{ inputs.email }}
16 changes: 14 additions & 2 deletions .github/actions/parse-semver/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ runs:
id: parse
shell: bash
run: |
FULL_VERSION="${{ inputs.input_string }}"
FULL_VERSION="$INPUTS_INPUT_STRING"
VERSION="${FULL_VERSION#v}"
# Filter out non-semver characters
Expand All @@ -57,8 +57,20 @@ runs:
echo "patch=$PATCH" >> "$GITHUB_OUTPUT"
echo "prerelease=$PRERELEASE" >> "$GITHUB_OUTPUT"
echo "fullversion=$FULL_VERSION" >> "$GITHUB_OUTPUT"
env:
INPUTS_INPUT_STRING: ${{ inputs.input_string }}

- name: Exit if major, minor, or patch not found
if: ${{ !steps.parse.outputs.major || !steps.parse.outputs.minor || !steps.parse.outputs.patch }}
uses: actions/github-script@v7
with:
script: core.setFailed("Error parsing semver ${{ inputs.input_string }}\nMajor:${{ steps.parse.outputs.major }}\nMinor:${{ steps.parse.outputs.minor }}\nPatch:${{ steps.parse.outputs.patch }}")
script: |
core.setFailed(`Error parsing semver: ${process.env.INPUTS_INPUT_STRING}
Major: ${process.env.STEPS_PARSE_MAJOR}
Minor: ${process.env.STEPS_PARSE_MINOR}
Patch: ${process.env.STEPS_PARSE_PATCH}`)
env:
INPUTS_INPUT_STRING: ${{ inputs.input_string }}
STEPS_PARSE_MAJOR: ${{ steps.parse.outputs.major }}
STEPS_PARSE_MINOR: ${{ steps.parse.outputs.minor }}
STEPS_PARSE_PATCH: ${{ steps.parse.outputs.patch }}
22 changes: 0 additions & 22 deletions .github/actions/renameMacPkg/action.yml

This file was deleted.

36 changes: 28 additions & 8 deletions .github/actions/versionInfo/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,42 @@ runs:
steps:
- id: getSha
shell: bash
run: echo "sha=$(npm view ${{ inputs.npmPackage }}@${{ inputs.version }} --json | jq -r '.gitHead[0:7]')" >> "$GITHUB_OUTPUT"
run: echo "sha=$(npm view $INPUTS_NPM_PACKAGE@$INPUTS_VERSION --json | jq -r '.gitHead[0:7]')" >> "$GITHUB_OUTPUT"
env:
INPUTS_NPM_PACKAGE: ${{ inputs.npmPackage }}
INPUTS_VERSION: ${{ inputs.version }}

- id: getNumericalVersion
shell: bash
run: echo "version=$(npm view ${{ inputs.npmPackage }}@${{ inputs.version }} --json | jq -r '.version')" >> "$GITHUB_OUTPUT"
run: echo "version=$(npm view $INPUTS_NPM_PACKAGE@$INPUTS_VERSION --json | jq -r '.version')" >> "$GITHUB_OUTPUT"
env:
INPUTS_NPM_PACKAGE: ${{ inputs.npmPackage }}
INPUTS_VERSION: ${{ inputs.version }}

- id: getCli
shell: bash
run: echo "cli=$(npm view ${{ inputs.npmPackage }}@${{ inputs.version }} --json | jq -r '.oclif.bin')" >> "$GITHUB_OUTPUT"
run: echo "cli=$(npm view $INPUTS_NPM_PACKAGE@$INPUTS_VERSION --json | jq -r '.oclif.bin')" >> "$GITHUB_OUTPUT"
env:
INPUTS_NPM_PACKAGE: ${{ inputs.npmPackage }}
INPUTS_VERSION: ${{ inputs.version }}

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

- run: echo "regex found version ${{ steps.getNumericalVersion.outputs.version }} with sha ${{ steps.getSha.outputs.sha }} for cli ${{ steps.getCli.outputs.cli }}"
shell: bash

- 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"
- name: Echo info
shell: bash
run: |
echo "[INFO] version-info outputs:"
echo "cli: $STEPS_GETCLI_CLI"
echo "version: $STEPS_GETNUMERICALVERSION_VERSION"
echo "sha: $STEPS_GETSHA_SHA"
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"
env:
STEPS_GETCLI_CLI: ${{ steps.getCli.outputs.cli }}
STEPS_GETNUMERICALVERSION_VERSION: ${{ steps.getNumericalVersion.outputs.version }}
STEPS_GETSHA_SHA: ${{ steps.getSha.outputs.sha }}
STEPS_GETS3FOLDER_FOLDER: ${{ steps.getS3Folder.outputs.folder }}
15 changes: 7 additions & 8 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,17 @@ jobs:
- uses: actions/checkout@v4
with:
token: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}

- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: npm

- run: npm install -g @salesforce/plugin-release-management --omit=dev

- name: run automerge command
if: ${{ !inputs.skipCI }}
env:
GITHUB_TOKEN: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN}}
run: sf-release dependabot:automerge --merge-method ${{ inputs.mergeMethod}} --max-version-bump ${{ inputs.maxVersionBump}} --owner $GITHUB_REPOSITORY_OWNER --repo $(basename $GITHUB_REPOSITORY)
- name: run automerge command
if: ${{ inputs.skipCI }}
run: sf-release dependabot:automerge --merge-method "$INPUTS_MERGE_METHOD" --max-version-bump "$INPUTS_MAX_VERSION_BUMP" --owner $GITHUB_REPOSITORY_OWNER --repo $(basename $GITHUB_REPOSITORY) ${{ inputs.skipCI && '--skip-ci' || '' }}
env:
GITHUB_TOKEN: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN}}
run: sf-release dependabot:automerge --merge-method ${{ inputs.mergeMethod}} --max-version-bump ${{ inputs.maxVersionBump}} --owner $GITHUB_REPOSITORY_OWNER --repo $(basename $GITHUB_REPOSITORY) --skip-ci
GITHUB_TOKEN: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
INPUTS_MERGE_METHOD: ${{ inputs.mergeMethod }}
INPUTS_MAX_VERSION_BUMP: ${{ inputs.maxVersionBump }}
19 changes: 11 additions & 8 deletions .github/workflows/create-github-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@ jobs:
# This will allow us to merge a prerelease PR into main and have it release as a normal release
if: github.ref_name != 'main'
run: |
if [ -n "${{ inputs.prerelease }}" ]; then
echo "Prerelease input passed in, using: ${{ inputs.prerelease }}"
echo "tag=${{ inputs.prerelease }}" >> "$GITHUB_OUTPUT"
elif [ -n "${{ steps.distTag.outputs.tag }}" ]; then
echo "Prerelease tag found in package.json, using: ${{ steps.distTag.outputs.tag }}"
echo "tag=${{ steps.distTag.outputs.tag }}" >> "$GITHUB_OUTPUT"
elif [[ ${{ github.ref_name }} =~ ^prerelease/.* ]]; then
echo "Prerelease branch found but no prerelease tag, using default: dev"
if [ -n "$INPUTS_PRERELEASE" ]; then
echo "[INFO] Prerelease input passed in, using: $INPUTS_PRERELEASE"
echo "tag=$INPUTS_PRERELEASE" >> "$GITHUB_OUTPUT"
elif [ -n "$STEPS_DISTTAG_TAG" ]; then
echo "[INFO] Prerelease tag found in package.json, using: $STEPS_DISTTAG_TAG"
echo "tag=$STEPS_DISTTAG_TAG" >> "$GITHUB_OUTPUT"
elif [[ "$GITHUB_REF_NAME" =~ ^prerelease/.* ]]; then
echo "[INFO] Prerelease branch found but no prerelease tag, using default: dev"
echo "tag=dev" >> "$GITHUB_OUTPUT"
fi
env:
INPUTS_PRERELEASE: ${{ inputs.prerelease }}
STEPS_DISTTAG_TAG: ${{ steps.distTag.outputs.tag }}

- name: Generate oclif readme
if: ${{ inputs.generate-readme }}
Expand Down
Loading

0 comments on commit 68b466e

Please sign in to comment.