Skip to content

Commit

Permalink
metadata, threshold: add short_sha
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjvs committed Aug 8, 2023
1 parent 1eb634a commit ee59089
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
40 changes: 24 additions & 16 deletions .github/workflows/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ on:
value: ${{ jobs.meta.outputs.description }}
topics:
description: Project topics in JSON array
value: ${{ jobs.meta.outputs.topicsJson }}
value: ${{ jobs.meta.outputs.topics }}
linuxName:
description: Versioned filename that would be given to a library for this project on Linux
value: ${{ jobs.meta.outputs.linuxName }}
Expand Down Expand Up @@ -87,6 +87,9 @@ on:
releasesUrl:
description: Project releases API URL
value: ${{ jobs.meta.outputs.releasesUrl }}
short_sha:
description: Short SHA of the commit being processed
value: ${{ jobs.meta.outputs.short_sha }}

jobs:
name:
Expand Down Expand Up @@ -118,6 +121,7 @@ jobs:
gitUrl: ${{ steps.url.outputs.gitUrl }}
tagsUrl: ${{ steps.url.outputs.tagsUrl }}
releasesUrl: ${{ steps.url.outputs.releasesUrl }}
short_sha: ${{ steps.api.outputs.short_sha }}

steps:
- name: Debug
Expand All @@ -136,21 +140,23 @@ jobs:
topics: ${{ toJSON(github.event.repository.topics) }}
run: |
# init
# shellcheck disable=SC2086
url="https://github.com/repos/${repo}"
echo "url is ${url}"
echo "url=${url}" >> $GITHUB_OUTPUT
echo "url=${url}" >> "$GITHUB_OUTPUT"
json=""
# Define function
updateValue() {
[[ "$1" != "" ]] && _var="$1" || exit 1
[[ "$2" != "" ]] && _term="$2" || _term="$1"
# if the value is an empty string or empty array
if [[ "${!_var}" =~ "^$|\[[[:space:]]*\]" ]] ; then
[[ "$json" == "" ]] && json=$(curl -s $url);
read "${_var}" <<< $(jq -r ".${_term}" <<< "$json")
if [[ "${!_var}" =~ ^$|\[[[:space:]]*\] ]] ; then
[[ "$json" == "" ]] && json=$(curl -s "$url");
# shellcheck disable=SC2162,SC2229
read "${_var}" <<< "$(jq -r ".${_term}" <<< "$json")"
fi
echo "${_var} is ${!_var}"
echo "${_var}=${!_var}" >> $GITHUB_OUTPUT
echo "${_var}=${!_var}" >> "$GITHUB_OUTPUT"
}
# Do work
updateValue "defaultBranch" "default_branch"
Expand All @@ -164,21 +170,22 @@ jobs:
jsonTopics=$(jq -r ".topics" <<< "$json")
echo "Retrieved topics are $jsonTopics"
bothTopicArrays="$topics $jsonTopics"
topics=$(jq -s -c 'add | unique' <<< $bothTopicArrays)
topics=$(jq -s -c 'add | unique' <<< "$bothTopicArrays")
echo "Final topics are $topics"
echo "topics=$topics" >> $GITHUB_OUTPUT
echo "topics=$topics" >> "$GITHUB_OUTPUT"
echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
- name: Get Branch
id: branch
env:
defaultBranch: ${{ steps.api.outputs.defaultBranch }}
run: |
currentBranch=${GITHUB_REF#refs/heads/}
echo Branches current $currentBranch default $defaultBranch
currentBranch="${GITHUB_REF#refs/heads/}"
echo "Branches - current: $currentBranch - default: $defaultBranch"
if [[ $currentBranch == refs/tags/* ]] ; then
currentBranch=$defaultBranch
currentBranch="$defaultBranch"
fi
echo "currentBranch=${currentBranch}" >> $GITHUB_OUTPUT
echo "currentBranch=${currentBranch}" >> "$GITHUB_OUTPUT"
- name: Links
id: url
Expand All @@ -195,8 +202,9 @@ jobs:
if [ "$homepage" == "" ] ; then
homepage="https://stirlinglabs.com"
fi
echo "homepage=${homepage}" >> $GITHUB_OUTPUT
echo "gitUrl=${gitUrl}" >> $GITHUB_OUTPUT
echo "tagsUrl=${tagsUrl}" >> $GITHUB_OUTPUT
echo "releasesUrl=${releasesUrl}" >> $GITHUB_OUTPUT
# shellcheck disable=SC2129
echo "homepage=${homepage}" >> "$GITHUB_OUTPUT"
echo "gitUrl=${gitUrl}" >> "$GITHUB_OUTPUT"
echo "tagsUrl=${tagsUrl}" >> "$GITHUB_OUTPUT"
echo "releasesUrl=${releasesUrl}" >> "$GITHUB_OUTPUT"
26 changes: 18 additions & 8 deletions .github/workflows/threshold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ on:
release:
description: "This version is a release"
value: ${{ jobs.check.outputs.release }}
sha:
description: "The SHA of the commit that was considered"
value: ${{ jobs.check.outputs.sha }}
short_sha:
description: "The short SHA of the commit that was considered"
value: ${{ jobs.check.outputs.short_sha }}

jobs:
check:
Expand All @@ -18,6 +24,8 @@ jobs:
outputs:
continue: ${{ steps.collate_checks.outputs.process }}
release: ${{ steps.released_check.outputs.release }}
sha: ${{ steps.collate_checks.outputs.sha }}
short_sha: ${{ steps.collate_checks.outputs.short_sha }}
steps:
- name: Dump GitHub context
if: false
Expand All @@ -33,7 +41,7 @@ jobs:
contains(github.event.head_commit.message, '[force-ci]') ||
contains(github.event.head_commit.message, '[forceci]')
run: |
echo "process=true" >> $GITHUB_OUTPUT
echo "process=true" >> "$GITHUB_OUTPUT"
- name: Check if PR is a draft
id: pr_draft_check
Expand All @@ -42,7 +50,7 @@ jobs:
env:
process: ${{ !github.event.pull_request.draft }}
run: |
echo "process=$process" >> $GITHUB_OUTPUT
echo "process=$process" >> "$GITHUB_OUTPUT"
- name: Check if this is a Release
id: released_check
Expand All @@ -51,8 +59,8 @@ jobs:
github.ref_type == 'tag' &&
startsWith(github.ref_name, 'v')
run: |
echo "process=false" >> $GITHUB_OUTPUT
echo "release=true" >> $GITHUB_OUTPUT
echo "process=false" >> "$GITHUB_OUTPUT"
echo "release=true" >> "$GITHUB_OUTPUT"
- name: Check if changes pushed
id: push_new_check
Expand All @@ -78,7 +86,7 @@ jobs:
steps.push_new_check.outcome == 'skipped'
run: |
echo "All checks skipped, I don't have any meaningful input, so let's skip processing."
echo "process=false" >> $GITHUB_OUTPUT
echo "process=false" >> "$GITHUB_OUTPUT"
- name: Collate Checks
id: collate_checks
Expand Down Expand Up @@ -115,8 +123,10 @@ jobs:
[[ "$push_new_result" == "true" ]] && message="changes were pushed to the repo"
[[ "$pr_draft_result" == "true" ]] && message="this is an active pull request"
[[ "$force_ci_result" == "true" ]] && message="it was forced by the commit message"
echo "### Processing continuing since ${message}." >> $GITHUB_STEP_SUMMARY
echo "### Processing continuing since ${message}." >> "$GITHUB_STEP_SUMMARY"
else
echo "### Continued processing does not appear to be necessary." >> $GITHUB_STEP_SUMMARY
echo "### Continued processing does not appear to be necessary." >> "$GITHUB_STEP_SUMMARY"
fi
echo "process=$process" >> $GITHUB_OUTPUT
# shellcheck disable=SC2129
echo "process=$process" >> "$GITHUB_OUTPUT"
echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"

0 comments on commit ee59089

Please sign in to comment.