From b3a831e7562b86eb9b2dfde9c80e233c0f7e1808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Wed, 12 Jul 2023 18:57:48 +0200 Subject: [PATCH 1/9] Update release notes action for new release model --- .../actions/create-release-notes/action.yml | 38 +++++++++++++++---- .github/workflows/onPush.yml | 10 +++++ .github/workflows/pr.yml | 5 +++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/.github/actions/create-release-notes/action.yml b/.github/actions/create-release-notes/action.yml index 4c44cdf12a0..6e89159e196 100644 --- a/.github/actions/create-release-notes/action.yml +++ b/.github/actions/create-release-notes/action.yml @@ -1,5 +1,12 @@ name: 'Create Release Notes' description: 'Creates the current releases release notes' +inputs: + tag-name: + description: 'Name of the tag that will be used for this release' + required: true + gh-token: + description: 'The GitHub token used to get details from the API' + required: true runs: using: 'composite' steps: @@ -9,15 +16,30 @@ runs: run: | mkdir -p ./app/build/outputs/ - echo "Previous Release Commit:" - git tag -l --sort=-creatordate | grep -v beta- | head -n 1 - previous=`git tag -l --sort=-creatordate | grep -v beta- | head -n 1` + echo "Previous Release Tag:" + TAG=`\ + curl --no-progress-meter --request GET \ + --url "https://api.github.com/repos/home-assistant/android/releases/latest" \ + --header "Accept: application/vnd.github+json" \ + --header "Authorization: Bearer ${{inputs.gh-token}}" \ + --header "X-GitHub-Api-Version: 2022-11-28" \ + | jq -r .tag_name + ` + echo $TAG - echo "# Changes:" > ./app/build/outputs/changelogGithub - echo "Changlog:" - git log --format="* %s" ${previous}..HEAD - git log --format="* %s" ${previous}..HEAD >> ./app/build/outputs/changelogGithub + echo "Full Changelog:" + CHANGELOG=`\ + curl --no-progress-meter --request POST \ + --url "https://api.github.com/repos/home-assistant/android/releases/generate-notes" \ + --header "Accept: application/vnd.github+json" \ + --header "Authorization: Bearer ${{inputs.gh-token}}" \ + --header "X-GitHub-Api-Version: 2022-11-28" \ + --data "{\"tag_name\":\"${{inputs.tag-name}}\",\"target_commitish\":\"master\",\"previous_tag_name\":\"$TAG\"}" \ + | jq -r .body + ` + echo $CHANGELOG + printf "$CHANGELOG" > ./app/build/outputs/changelogGithub - echo "Beta Changelog" + echo "Beta Changelog:" git log --format="* %s" HEAD^..HEAD git log --format="* %s" HEAD^..HEAD > ./app/build/outputs/changelogBeta diff --git a/.github/workflows/onPush.yml b/.github/workflows/onPush.yml index 96c92a200ee..39eda28e8ca 100644 --- a/.github/workflows/onPush.yml +++ b/.github/workflows/onPush.yml @@ -15,6 +15,8 @@ jobs: app_build: name: Github, Firebase, and Sentry Release runs-on: ubuntu-latest + permissions: + contents: write steps: - uses: actions/checkout@v3 with: @@ -54,6 +56,9 @@ jobs: - uses: ./.github/actions/create-release-notes name: Create Release Notes + with: + tag-name: ${{ steps.rel_number.outputs.version }} + gh-token: ${{ secrets.GITHUB_TOKEN }} - uses: ./.github/actions/download-translations name: Download Translations @@ -118,6 +123,8 @@ jobs: runs-on: ubuntu-latest concurrency: group: playstore_deploy + permissions: + contents: write steps: - uses: actions/checkout@v3 with: @@ -157,6 +164,9 @@ jobs: - uses: ./.github/actions/create-release-notes name: Create Release Notes + with: + tag-name: ${{ steps.rel_number.outputs.version }} + gh-token: ${{ secrets.GITHUB_TOKEN }} - uses: ./.github/actions/download-translations name: Download Translations diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index bd2249de9d5..4bcc9d1f86c 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -63,6 +63,8 @@ jobs: pr_build: runs-on: ubuntu-latest + permissions: + contents: write steps: - uses: actions/checkout@v3 with: @@ -104,6 +106,9 @@ jobs: - uses: ./.github/actions/create-release-notes name: Create Release Notes + with: + tag-name: ${{ steps.rel_number.outputs.version }} + gh-token: ${{ secrets.GITHUB_TOKEN }} - name: Build Debug APK run: ./gradlew assembleDebug From c8aa5c30b585f52fce1cb46286acc7d6bece853f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Tue, 1 Aug 2023 20:31:38 +0200 Subject: [PATCH 2/9] Include newlines --- .github/actions/create-release-notes/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/create-release-notes/action.yml b/.github/actions/create-release-notes/action.yml index 6e89159e196..19d59b041b8 100644 --- a/.github/actions/create-release-notes/action.yml +++ b/.github/actions/create-release-notes/action.yml @@ -37,7 +37,7 @@ runs: --data "{\"tag_name\":\"${{inputs.tag-name}}\",\"target_commitish\":\"master\",\"previous_tag_name\":\"$TAG\"}" \ | jq -r .body ` - echo $CHANGELOG + echo -e $CHANGELOG printf "$CHANGELOG" > ./app/build/outputs/changelogGithub echo "Beta Changelog:" From b0b4d8825f29677891bb75667a9318036340675b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Tue, 1 Aug 2023 20:49:31 +0200 Subject: [PATCH 3/9] Switch to actions/github-script --- .../actions/create-release-notes/action.yml | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/.github/actions/create-release-notes/action.yml b/.github/actions/create-release-notes/action.yml index 19d59b041b8..7b00853f23b 100644 --- a/.github/actions/create-release-notes/action.yml +++ b/.github/actions/create-release-notes/action.yml @@ -10,6 +10,29 @@ inputs: runs: using: 'composite' steps: + - name: Get Previous Release Tag + uses: actions/github-script@v6 + id: release-tag + with: + github_token: ${{ inputs.gh-token }} + script: | + return await github.rest.repos.getLatestRelease({ + home-assistant, + android + }) + - name: Get Generated Release Notes + uses: actions/github-script@v6 + id: generate-notes + with: + github_token: ${{ inputs.gh-token }} + script: | + return await github.rest.repos.generateReleaseNotes({ + home-assistant, + android, + ${{inputs.tag_name}}, + master, + ${{steps.release-tag.outputs.result.tag_name}}, + }) - name: Generate Release Notes id: version-generator shell: bash @@ -17,26 +40,10 @@ runs: mkdir -p ./app/build/outputs/ echo "Previous Release Tag:" - TAG=`\ - curl --no-progress-meter --request GET \ - --url "https://api.github.com/repos/home-assistant/android/releases/latest" \ - --header "Accept: application/vnd.github+json" \ - --header "Authorization: Bearer ${{inputs.gh-token}}" \ - --header "X-GitHub-Api-Version: 2022-11-28" \ - | jq -r .tag_name - ` - echo $TAG + echo "${{steps.release-tag.outputs.result.tag_name}}" echo "Full Changelog:" - CHANGELOG=`\ - curl --no-progress-meter --request POST \ - --url "https://api.github.com/repos/home-assistant/android/releases/generate-notes" \ - --header "Accept: application/vnd.github+json" \ - --header "Authorization: Bearer ${{inputs.gh-token}}" \ - --header "X-GitHub-Api-Version: 2022-11-28" \ - --data "{\"tag_name\":\"${{inputs.tag-name}}\",\"target_commitish\":\"master\",\"previous_tag_name\":\"$TAG\"}" \ - | jq -r .body - ` + CHANGELOG="${{steps.generate-notes.outputs.result.body}}" echo -e $CHANGELOG printf "$CHANGELOG" > ./app/build/outputs/changelogGithub From 572d19493fd1793fba3910553087f5b565a35961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Tue, 1 Aug 2023 20:50:35 +0200 Subject: [PATCH 4/9] Fix token input --- .github/actions/create-release-notes/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/create-release-notes/action.yml b/.github/actions/create-release-notes/action.yml index 7b00853f23b..18c80886b6c 100644 --- a/.github/actions/create-release-notes/action.yml +++ b/.github/actions/create-release-notes/action.yml @@ -14,7 +14,7 @@ runs: uses: actions/github-script@v6 id: release-tag with: - github_token: ${{ inputs.gh-token }} + github-token: ${{ inputs.gh-token }} script: | return await github.rest.repos.getLatestRelease({ home-assistant, @@ -24,7 +24,7 @@ runs: uses: actions/github-script@v6 id: generate-notes with: - github_token: ${{ inputs.gh-token }} + github-token: ${{ inputs.gh-token }} script: | return await github.rest.repos.generateReleaseNotes({ home-assistant, From bfe8fd5b15e3675fc80d89385ad0f7757b3964e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Tue, 1 Aug 2023 20:58:53 +0200 Subject: [PATCH 5/9] Named arguments, get owner/repo from context --- .github/actions/create-release-notes/action.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/actions/create-release-notes/action.yml b/.github/actions/create-release-notes/action.yml index 18c80886b6c..43b1cec9062 100644 --- a/.github/actions/create-release-notes/action.yml +++ b/.github/actions/create-release-notes/action.yml @@ -17,8 +17,8 @@ runs: github-token: ${{ inputs.gh-token }} script: | return await github.rest.repos.getLatestRelease({ - home-assistant, - android + owner: context.repo.owner, + repo: context.repo.repo, }) - name: Get Generated Release Notes uses: actions/github-script@v6 @@ -27,11 +27,11 @@ runs: github-token: ${{ inputs.gh-token }} script: | return await github.rest.repos.generateReleaseNotes({ - home-assistant, - android, - ${{inputs.tag_name}}, - master, - ${{steps.release-tag.outputs.result.tag_name}}, + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: "${{inputs.tag_name}}", + target_commitish: "master", + previous_tag_name: "${{steps.release-tag.outputs.result.tag_name}}", }) - name: Generate Release Notes id: version-generator From 7fbe64ed30535ecbfa0a606b8edbcf9cee0c70a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Tue, 1 Aug 2023 21:13:14 +0200 Subject: [PATCH 6/9] Return specific data and update vars --- .../actions/create-release-notes/action.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/actions/create-release-notes/action.yml b/.github/actions/create-release-notes/action.yml index 43b1cec9062..ebe7d327e4a 100644 --- a/.github/actions/create-release-notes/action.yml +++ b/.github/actions/create-release-notes/action.yml @@ -12,27 +12,29 @@ runs: steps: - name: Get Previous Release Tag uses: actions/github-script@v6 - id: release-tag + id: latest-release-tag with: github-token: ${{ inputs.gh-token }} script: | - return await github.rest.repos.getLatestRelease({ + const { data } = await github.rest.repos.getLatestRelease({ owner: context.repo.owner, repo: context.repo.repo, }) + return data.tag_name - name: Get Generated Release Notes uses: actions/github-script@v6 id: generate-notes with: github-token: ${{ inputs.gh-token }} script: | - return await github.rest.repos.generateReleaseNotes({ + const { data } = await github.rest.repos.generateReleaseNotes({ owner: context.repo.owner, repo: context.repo.repo, - tag_name: "${{inputs.tag_name}}", - target_commitish: "master", - previous_tag_name: "${{steps.release-tag.outputs.result.tag_name}}", + tag_name: '${{ inputs.tag_name }}', + target_commitish: 'master', + previous_tag_name: '${{ steps.latest-release-tag.outputs.result }}', }) + return data.body - name: Generate Release Notes id: version-generator shell: bash @@ -40,10 +42,10 @@ runs: mkdir -p ./app/build/outputs/ echo "Previous Release Tag:" - echo "${{steps.release-tag.outputs.result.tag_name}}" + echo "${{steps.latest-release-tag.outputs.result}}" echo "Full Changelog:" - CHANGELOG="${{steps.generate-notes.outputs.result.body}}" + CHANGELOG="${{ steps.generate-notes.outputs.result }}" echo -e $CHANGELOG printf "$CHANGELOG" > ./app/build/outputs/changelogGithub From 71d3c26da0dfcfd503d0b7aafd2ad2b4c0d130d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Tue, 1 Aug 2023 21:17:12 +0200 Subject: [PATCH 7/9] Last fixes, hopefully --- .github/actions/create-release-notes/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/create-release-notes/action.yml b/.github/actions/create-release-notes/action.yml index ebe7d327e4a..b7ca9d95d31 100644 --- a/.github/actions/create-release-notes/action.yml +++ b/.github/actions/create-release-notes/action.yml @@ -30,7 +30,7 @@ runs: const { data } = await github.rest.repos.generateReleaseNotes({ owner: context.repo.owner, repo: context.repo.repo, - tag_name: '${{ inputs.tag_name }}', + tag_name: '${{ inputs.tag-name }}', target_commitish: 'master', previous_tag_name: '${{ steps.latest-release-tag.outputs.result }}', }) @@ -42,7 +42,7 @@ runs: mkdir -p ./app/build/outputs/ echo "Previous Release Tag:" - echo "${{steps.latest-release-tag.outputs.result}}" + echo "${{ steps.latest-release-tag.outputs.result }}" echo "Full Changelog:" CHANGELOG="${{ steps.generate-notes.outputs.result }}" From ace72d08eb62f09f1cdf14f74fb643924817e9bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Tue, 1 Aug 2023 21:21:58 +0200 Subject: [PATCH 8/9] Set result encoding to string --- .github/actions/create-release-notes/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/create-release-notes/action.yml b/.github/actions/create-release-notes/action.yml index b7ca9d95d31..b8fcd36902f 100644 --- a/.github/actions/create-release-notes/action.yml +++ b/.github/actions/create-release-notes/action.yml @@ -15,6 +15,7 @@ runs: id: latest-release-tag with: github-token: ${{ inputs.gh-token }} + result-encoding: string script: | const { data } = await github.rest.repos.getLatestRelease({ owner: context.repo.owner, @@ -26,6 +27,7 @@ runs: id: generate-notes with: github-token: ${{ inputs.gh-token }} + result-encoding: string script: | const { data } = await github.rest.repos.generateReleaseNotes({ owner: context.repo.owner, From 4e2873d24f04f36f6a03328a1e0f8ebe777f1ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Tue, 1 Aug 2023 21:28:41 +0200 Subject: [PATCH 9/9] Prevent echo from printing directory contents --- .github/actions/create-release-notes/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/create-release-notes/action.yml b/.github/actions/create-release-notes/action.yml index b8fcd36902f..713e0e90e17 100644 --- a/.github/actions/create-release-notes/action.yml +++ b/.github/actions/create-release-notes/action.yml @@ -48,7 +48,7 @@ runs: echo "Full Changelog:" CHANGELOG="${{ steps.generate-notes.outputs.result }}" - echo -e $CHANGELOG + echo -e "$CHANGELOG" printf "$CHANGELOG" > ./app/build/outputs/changelogGithub echo "Beta Changelog:"