Skip to content

Commit

Permalink
Move run script in test.yml to convert.sh file
Browse files Browse the repository at this point in the history
  • Loading branch information
jun66j5 committed Jan 6, 2024
1 parent c68373b commit 69b3a12
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 78 deletions.
90 changes: 12 additions & 78 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
inputs:
os:
description: 'Runs on'
required: true
required: false
type: string
default: 'ubuntu-22.04 macos-12 windows-2022'
targets:
Expand Down Expand Up @@ -36,87 +36,18 @@ jobs:
dependencies: ${{ steps.convert.outputs.dependencies }}

steps:
- name: Show inputs
env:
INPUTS: ${{ toJSON(inputs) }}
run: |
set -ex
{
echo '### Inputs:'
echo '```json'
echo "$INPUTS"
echo '```'
} >>"$GITHUB_STEP_SUMMARY"
- name: Checkout
uses: actions/checkout@v4

- name: Convert inputs to json outputs
id: convert
env:
INPUTS: ${{ toJSON(inputs) }}
run: |
set -ex
os_json() {
local name="$1"
local value="$(
cat "$tmpfile" |
jq -Mc '.os | split(" ") | map(select(startswith("'"$name"'-")))'
)"
echo "$name=$value"
}
targets_json() {
local name="$1"
local value="$(
cat "$tmpfile" |
jq -Mc '."'"$name"'" | split(" ") | map(select(.!=""))'
)"
echo "$name=$value"
}
svn_json() {
local name="$1"
local value="$(jq -r ".\"$name\"" <"$tmpfile")"
case "$value" in
apache/subversion@*|$GITHUB_REPOSITORY_OWNER/*@*)
value="$(
echo "$value" |
jq -RMc 'split("@") | {repository: .[0], ref: .[1]}'
)"
;;
https://dist.apache.org/*/subversion-*.tar.bz2)
value="$(echo "$value" | jq -RMc '{archive: .}')"
;;
*)
echo "Unrecognized inputs.subversion: '$value'" 1>&2
exit 1
;;
esac
echo "$name=$value"
}
deps_json() {
local name="$1"
local value="$(
cat "$tmpfile" |
jq -Mc '."'"$name"'" | split(" ") | map(select(.!="") | split("=") | {(.[0]): .[1]}) | add'
)"
echo "$name=$value"
}
tmpfile="$(mktemp)"
echo "$INPUTS" >"$tmpfile"
{
os_json 'ubuntu'
os_json 'macos'
os_json 'windows'
targets_json 'targets'
svn_json 'subversion'
deps_json 'dependencies'
} >>"$GITHUB_OUTPUT"
{
echo '### Outputs:'
echo '```'
cat "$GITHUB_OUTPUT"
echo '```'
} >>"$GITHUB_STEP_SUMMARY"
run: ./convert.sh

- name: Cache Subversion archives
if: ${{ fromJson(steps.convert.outputs.subversion).archive }}
if: ${{ steps.convert.outputs.subversion &&
fromJson(steps.convert.outputs.subversion).archive }}
uses: actions/cache@v3
with:
path: arc
Expand All @@ -127,7 +58,8 @@ jobs:
arc--
- name: Cache junit jar file
if: ${{ contains(fromJson(steps.convert.outputs.targets), 'javahl') }}
if: ${{ steps.convert.outputs.targets &&
contains(fromJson(steps.convert.outputs.targets), 'javahl') }}
uses: actions/cache@v3
with:
path: arc
Expand All @@ -138,7 +70,8 @@ jobs:
arc--
- name: Download Subversion archives
if: ${{ fromJson(steps.convert.outputs.subversion).archive }}
if: ${{ steps.convert.outputs.subversion &&
fromJson(steps.convert.outputs.subversion).archive }}
env:
SVNARC: ${{ fromJson(steps.convert.outputs.subversion).archive }}
run: |
Expand All @@ -147,7 +80,8 @@ jobs:
wget -nv -N -P arc "$SVNARC" "${SVNARC%.tar.bz2}.zip"
- name: Download junit jar file
if: ${{ contains(fromJson(steps.convert.outputs.targets), 'javahl') }}
if: ${{ steps.convert.outputs.targets &&
contains(fromJson(steps.convert.outputs.targets), 'javahl') }}
env:
JUNIT_VER: ${{ fromJson(steps.convert.outputs.dependencies).junit }}
run: |
Expand Down
72 changes: 72 additions & 0 deletions convert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#! /bin/sh

set -ex

os_json() {
local name="$1"
local value="$(
cat "$tmpfile" |
jq -Mc '.os | split(" ") | map(select(startswith("'"$name"'-")))'
)"
echo "$name=$value"
}

targets_json() {
local name="$1"
local value="$(
cat "$tmpfile" |
jq -Mc '."'"$name"'" | split(" ") | map(select(.!=""))'
)"
echo "$name=$value"
}

svn_json() {
local name="$1"
local value="$(jq -r ".\"$name\"" <"$tmpfile")"
case "$value" in
apache/subversion@*|$GITHUB_REPOSITORY_OWNER/*@*)
value="$(
echo "$value" |
jq -RMc 'split("@") | {repository: .[0], ref: .[1]}'
)"
;;
https://dist.apache.org/*/subversion-*.tar.bz2)
value="$(echo "$value" | jq -RMc '{archive: .}')"
;;
*)
echo "Unrecognized inputs.subversion: '$value'" 1>&2
exit 1
;;
esac
echo "$name=$value"
}

deps_json() {
local name="$1"
local value="$(
cat "$tmpfile" |
jq -Mc '."'"$name"'" | split(" ") | map(select(.!="") | split("=") | {(.[0]): .[1]}) | add'
)"
echo "$name=$value"
}

tmpfile="$(mktemp)"
echo "$INPUTS" >"$tmpfile"
{
os_json 'ubuntu'
os_json 'macos'
os_json 'windows'
targets_json 'targets'
svn_json 'subversion'
deps_json 'dependencies'
} >>"$GITHUB_OUTPUT"
{
echo '### Inputs:'
echo '```json'
cat "$tmpfile"
echo '```'
echo '### Outputs:'
echo '```'
cat "$GITHUB_OUTPUT"
echo '```'
} >>"$GITHUB_STEP_SUMMARY"

0 comments on commit 69b3a12

Please sign in to comment.