From bf3737b33dbc9572adf3d76d54e5158b7659555b Mon Sep 17 00:00:00 2001 From: Petro Kurbatskyi <67897517+ibexa-yuna@users.noreply.github.com> Date: Mon, 7 Nov 2022 11:13:23 +0100 Subject: [PATCH] IBX-4145: Updated changelog generator (#5) --- .github/workflows/release_tag.yml | 38 ++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release_tag.yml b/.github/workflows/release_tag.yml index af93551e..18705f05 100644 --- a/.github/workflows/release_tag.yml +++ b/.github/workflows/release_tag.yml @@ -24,13 +24,30 @@ jobs: name: Gather latest package information run: | OUT=$(jq --slurp '[.[].packages[] | select(.name | contains("ezsystems") or contains("ibexa")) | [.name, .version] | { name: (.[0]), version: .[1] }]' composer.lock) - echo "::set-output name=lock::$( echo "$OUT" | sed ':a;N;$!ba;s/\n/%0A/g' )" + echo "lock=$( echo "$OUT" | sed ':a;N;$!ba;s/\n//g' )" >> $GITHUB_OUTPUT + + - name: Get previous last full release + id: prevfull + run: | + OUT=$(hub api /repos/${{ github.repository }}/releases | jq -r -s '[ .[][].tag_name | select(. | contains("rc") or contains("beta") or contains("alpha") | not) ] | first') + echo "tag=$( echo "$OUT" )" >> $GITHUB_OUTPUT + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get previous last full release + id: prevfull + run: | + OUT=$(hub api /repos/${{ github.repository }}/releases | jq -r -s '[ .[][].tag_name | select(. | contains("rc") or contains("beta") or contains("alpha") | not) ] | first') + echo "::set-output name=tag::$( echo "$OUT" | sed ':a;N;$!ba;s/\n/%0A/g' )" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get previous release tag based on type id: prevrelease uses: ibexa/version-logic-action@master with: currentTag: ${{ env.BUILD_TAG }} + prevFullTag: ${{ steps.prevfull.outputs.tag }} # checkout previous tag - uses: actions/checkout@v2 @@ -42,7 +59,7 @@ jobs: name: Gather previous package information run: | OUT=$(jq --slurp '[.[].packages[] | select(.name | contains("ezsystems") or contains("ibexa")) | [.name, .version] | { name: (.[0]), version: .[1] }]' composer.lock) - echo "::set-output name=lock::$( echo "$OUT" | sed ':a;N;$!ba;s/\n/%0A/g' )" + echo "lock=$( echo "$OUT" | sed ':a;N;$!ba;s/\n//g' )" >> $GITHUB_OUTPUT # do some magic comparing those outputs - id: output_data @@ -56,8 +73,15 @@ jobs: cat > $FILE2 <<'EOF' ${{ steps.currentLock.outputs.lock }} EOF - OUT=$(jq -s 'flatten | group_by(.name)' $FILE1 $FILE2 | jq -s '[ .[][] | {name: (.[0].name), versions: [ .[0].version, .[1].version ] | unique} | select(.versions | length > 1) ]') - echo "::set-output name=matrix::$( echo "$OUT" | sed ':a;N;$!ba;s/\n/%0A/g' )" + # Get only changed packages and sort versions in ascending order + # Step 1: Merge composer.json from two versions, grouping by .name + # Step 2: Take .versions key and remove duplicate versions (means this bundle did not change) + # Step 3: Select only those bundles that have more than 1 version in .versions + # Step 4: Sort versions + # Step 5: (outer brackets) Wrap that into JSON list of objects + # Note: zzzz is added as an additional suffix to properly sort out alpha/beta/etc pre-releases (v2.5.1-alphazzzz < v2.5.1zzzz) + OUT=$(jq -s 'flatten | group_by(.name)' $FILE1 $FILE2 | jq -s '[ .[][] | {name: (.[0].name), versions: [ .[0].version, .[1].version ] | unique} | select(.versions | length > 1) ] | .[].versions |= sort_by( . + "zzzz" | [scan("[0-9]+|[a-z]+")] | map(tonumber? // .) )') + echo "matrix=$( echo "$OUT" | sed ':a;N;$!ba;s/\n//g' )" >> $GITHUB_OUTPUT # this step is needed, so the output gets to the next defined job outputs: @@ -116,7 +140,9 @@ jobs: python main.py >> generator_output echo '' >> generator_output done - echo "::set-output name=output::$( cat generator_output | sed ':a;N;$!ba;s/\n/%0A/g' )" + echo "CHANGELOG_OUTPUT<> $GITHUB_ENV + echo "$(cat generator_output)" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV - name: Create Release id: create_release @@ -124,7 +150,7 @@ jobs: with: tag_name: ${{ env.BUILD_TAG }} body: | - ${{ steps.generator.outputs.output }} + ${{ env.CHANGELOG_OUTPUT }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}