Skip to content

Commit

Permalink
feat: preserve source information in release.json artifacts (#82)
Browse files Browse the repository at this point in the history
* docs: update CHANGELOG.md

* feat: preserve source information in release.json artifacts

* fix: name extraction in release workflows

* chore: use fetch instead of api get

* chore: fetch from origin

* fix: expect version to be string

* fix: restore worspace package version

* chore: simplify while in version check

* chore: set version before loop

* fix: move if

* fix: add missing parentheses

* chore: aggregate to an array

* fix: pretty print json aggregate

* fix: sha
  • Loading branch information
galargh authored Jul 28, 2024
1 parent b99cede commit 7e462cc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
40 changes: 27 additions & 13 deletions .github/workflows/release-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
outputs:
json:
description: JSON aggregation of release.json artifacts
value: ${{ toJSON(jobs.aggregate.outputs.json) }}
value: ${{ jobs.aggregate.outputs.json }}

jobs:
release-check:
Expand Down Expand Up @@ -71,19 +71,30 @@ jobs:
HEAD_SHA: ${{ fromJSON(steps.pr.outputs.json).head.sha }}
run: |
root="$(dirname "$SOURCE")"
source="$(basename "$SOURCE")"
echo "root=$root" | tee -a $GITHUB_OUTPUT
echo "source=$source" | tee -a $GITHUB_OUTPUT
if [[ "$root" == "." ]]; then
prefix="v"
else
prefix="${root}${SEPARATOR}v"
name="$(yq -r '.package.name // .name // "'"$root"'"' "$root/$source")"
prefix="${name}${SEPARATOR}v"
fi
echo "prefix=$prefix" | tee -a $GITHUB_OUTPUT
# If `version.json` file doesn't exists, `version` is `""` and `404` is printed on stderr.
# The step won't be marked as a failure though because the error happens in a subshell.
gh api -X GET "repos/$HEAD_FULL_NAME/contents/$SOURCE" -f ref="$HEAD_SHA" --jq '.content' | base64 -d > $SOURCE
version="$(yq -r '.workspace.package.version // .package.version // .version // ""' "$SOURCE")"
git checkout HEAD -- "$SOURCE"
version="${version#"$prefix"}"
git fetch origin "$HEAD_SHA"
while [[ -z "$version" ]]; do
echo "Checking $root/$source"
if [[ -f "$root/$source" ]]; then
git checkout "$HEAD_SHA" -- "$root/$source"
version="$(yq -r '.workspace.package.version // .package.version // .version | select(type == "!!str")' "$root/$source")"
git checkout HEAD -- "$root/$source"
version="${version#v}"
fi
if [[ "$root" == "." ]]; then
break
fi
root="$(dirname "$root")"
done
echo "version=$version" | tee -a $GITHUB_OUTPUT
echo "tag=${prefix}${version}" | tee -a $GITHUB_OUTPUT
- id: branch
Expand Down Expand Up @@ -313,7 +324,8 @@ jobs:
"url": "${{ steps.release.outputs.url }}",
"id": "${{ steps.release.outputs.id }}",
"upload_url": "${{ steps.release.outputs.upload_url }}",
"assets": ${{ steps.release.outputs.assets }}
"assets": ${{ steps.release.outputs.assets }},
"source": "${{ matrix.source }}"
}
run: |
jq . <<< "$RELEASE" > release.json
Expand All @@ -328,18 +340,20 @@ jobs:
needs: [release-check]
runs-on: ubuntu-latest
outputs:
json: ${{ steps.aggregate.outputs.json }}
json: ${{ toJSON(fromJSON(steps.aggregate.outputs.json)) }}
steps:
- uses: actions/download-artifact@v4
- id: aggregate
run: |
echo "json<<EOF" >> $GITHUB_OUTPUT
echo "{" | tee -a $GITHUB_OUTPUT
echo "[" | tee -a $GITHUB_OUTPUT
for d in *; do
f="$d/release.json"
if [[ -d "$d" && -f "$f" ]]; then
echo "\"$d\": $(jq . "$f")" | tee -a $GITHUB_OUTPUT
echo "$comma" | tee -a $GITHUB_OUTPUT
jq . "$f" | tee -a $GITHUB_OUTPUT
comma=","
fi
done
echo "}" | tee -a $GITHUB_OUTPUT
echo "]" | tee -a $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
34 changes: 25 additions & 9 deletions .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
outputs:
json:
description: JSON aggregation of release.json artifacts
value: ${{ toJSON(jobs.aggregate.outputs.json) }}
value: ${{ jobs.aggregate.outputs.json }}
secrets:
UCI_GITHUB_TOKEN:
required: false
Expand All @@ -38,14 +38,27 @@ jobs:
SEPARATOR: ${{ inputs.separator }}
run: |
root="$(dirname "$SOURCE")"
source="$(basename "$SOURCE")"
echo "root=$root" | tee -a $GITHUB_OUTPUT
echo "source=$source" | tee -a $GITHUB_OUTPUT
if [[ "$root" == "." ]]; then
prefix="v"
else
prefix="${root}${SEPARATOR}v"
name="$(yq -r '.package.name // .name // "'"$root"'"' "$root/$source")"
prefix="${name}${SEPARATOR}v"
fi
echo "prefix=$prefix" | tee -a $GITHUB_OUTPUT
version="$(yq -r '.workspace.package.version // .package.version // .version // ""' "$SOURCE")"
version="${version#"$prefix"}"
while [[ -z "$version" ]]; do
echo "Checking $root/$source"
if [[ -f "$root/$source" ]]; then
version="$(yq -r '.workspace.package.version // .package.version // .version | select(type == "!!str")' "$root/$source")"
version="${version#v}"
fi
if [[ "$root" == "." ]]; then
break
fi
root="$(dirname "$root")"
done
echo "version=$version" | tee -a $GITHUB_OUTPUT
echo "tag=${prefix}${version}" | tee -a $GITHUB_OUTPUT
- id: latest
Expand Down Expand Up @@ -150,7 +163,8 @@ jobs:
"id": "${{ steps.release.outputs.id }}",
"upload_url": "${{ steps.release.outputs.upload_url }}",
"assets": ${{ steps.release.outputs.assets }},
"make_latest": ${{ steps.version.outputs.prefix == 'v' && steps.version.outputs.tag == steps.latest.outputs.latest }}
"make_latest": ${{ steps.version.outputs.prefix == 'v' && steps.version.outputs.tag == steps.latest.outputs.latest }},
"source": "${{ matrix.source }}"
}
run: |
jq . <<< "$RELEASE" > release.json
Expand All @@ -165,18 +179,20 @@ jobs:
needs: [releaser]
runs-on: ubuntu-latest
outputs:
json: ${{ steps.aggregate.outputs.json }}
json: ${{ toJSON(fromJSON(steps.aggregate.outputs.json)) }}
steps:
- uses: actions/download-artifact@v4
- id: aggregate
run: |
echo "json<<EOF" >> $GITHUB_OUTPUT
echo "{" | tee -a $GITHUB_OUTPUT
echo "[" | tee -a $GITHUB_OUTPUT
for d in *; do
f="$d/release.json"
if [[ -d "$d" && -f "$f" ]]; then
echo "\"$d\": $(jq . "$f")" | tee -a $GITHUB_OUTPUT
echo "$comma" | tee -a $GITHUB_OUTPUT
jq . "$f" | tee -a $GITHUB_OUTPUT
comma=","
fi
done
echo "}" | tee -a $GITHUB_OUTPUT
echo "]" | tee -a $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- preserve source information in release.json artifacts

### Changed
- try finding version in parent sources
- retrieve subpackage name from .package.name or .name field of the source

## [1.0.8] - 2024-07-25
### Added
Expand Down

0 comments on commit 7e462cc

Please sign in to comment.