From 7e462ccd793ed7ede542fbd8b51944c0f84e79c4 Mon Sep 17 00:00:00 2001 From: Piotr Galar Date: Sun, 28 Jul 2024 09:44:30 +0100 Subject: [PATCH] feat: preserve source information in release.json artifacts (#82) * 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 --- .github/workflows/release-check.yml | 40 +++++++++++++++++++---------- .github/workflows/releaser.yml | 34 +++++++++++++++++------- CHANGELOG.md | 6 +++++ 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml index 451a47b..800f508 100644 --- a/.github/workflows/release-check.yml +++ b/.github/workflows/release-check.yml @@ -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: @@ -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 @@ -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 @@ -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<> $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 diff --git a/.github/workflows/releaser.yml b/.github/workflows/releaser.yml index f96eda9..dafef75 100644 --- a/.github/workflows/releaser.yml +++ b/.github/workflows/releaser.yml @@ -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 @@ -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 @@ -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 @@ -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<> $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 diff --git a/CHANGELOG.md b/CHANGELOG.md index ae8a174..7f69678 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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