diff --git a/.github/workflows/build_app.yml b/.github/workflows/build_app.yml index 750a023..bbb9b10 100644 --- a/.github/workflows/build_app.yml +++ b/.github/workflows/build_app.yml @@ -17,12 +17,13 @@ concurrency: jobs: prepare-build: + if: github.event.inputs.git-ref != '' runs-on: ubuntu-latest outputs: - COMMIT_COUNT: ${{ steps.prepare_env.outputs.COMMIT_COUNT }} - CURRENT_SHA: ${{ steps.prepare_env.outputs.CURRENT_SHA }} - PREV_RELEASE_SHA: ${{ steps.prepare_env.outputs.PREV_RELEASE_SHA }} - COMMIT_LOGS: ${{ steps.prepare_env.outputs.COMMIT_LOGS }} + COMMIT_COUNT: ${{ steps.current_commit.outputs.COMMIT_COUNT }} + CURRENT_SHA: ${{ steps.current_commit.outputs.CURRENT_SHA }} + PREV_RELEASE_SHA: ${{ steps.previous_commit.outputs.PREV_RELEASE_SHA }} + COMMIT_LOGS: ${{ steps.commit_logs.outputs.COMMIT_LOGS }} TAG_PREFIX: ${{ steps.prepare_env.outputs.TAG_PREFIX }} ARTIFACTS_PREFIX: ${{ steps.prepare_env.outputs.ARTIFACTS_PREFIX }} BUILD_TYPE_NAME: ${{ steps.prepare_env.outputs.BUILD_TYPE_NAME }} @@ -46,28 +47,55 @@ jobs: exclude_types: "draft|prerelease" view_top: 1 - - name: Prepare env - id: prepare_env + - name: Curren commit + id: current_commit run: | set -e commit_count=$(git rev-list --count HEAD) + echo "COMMIT_COUNT=$commit_count" echo "COMMIT_COUNT=$commit_count" >> $GITHUB_OUTPUT current_sha=$(git rev-parse --short HEAD) + echo "CURRENT_SHA=$current_sha" echo "CURRENT_SHA=$current_sha" >> $GITHUB_OUTPUT + - name: Previous commit + id: previous_commit + run: | + set -e + prev_commit_count=$(echo "${{ steps.last_release.outputs.tag_name }}" | sed -e "s/^r//") - commit_count_diff=$(expr $commit_count - $prev_commit_count) + echo "prev_commit_count=$prev_commit_count" + + # Fake at least 1 commits (to avoid no changes) + if [ "${{ steps.current_commit.outputs.COMMIT_COUNT }}" -gt "$prev_commit_count" ]; then + commit_count_diff="$(expr ${{ steps.current_commit.outputs.COMMIT_COUNT }} - $prev_commit_count)" + else + commit_count_diff=1 + fi + + echo "commit_count_diff=$commit_count_diff" prev_release_sha=$(git rev-parse --short HEAD~$commit_count_diff) + echo "PREV_RELEASE_SHA=$prev_release_sha" echo "PREV_RELEASE_SHA=$prev_release_sha" >> $GITHUB_OUTPUT + - name: Commit logs + id: commit_logs + run: | + set -e + echo "COMMIT_LOGS<<{delimiter} $(curl -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/komikku-app/komikku/compare/$prev_release_sha...$current_sha" \ + "https://api.github.com/repos/komikku-app/komikku/compare/${{ steps.previous_commit.outputs.PREV_RELEASE_SHA }}...${{ steps.current_commit.outputs.CURRENT_SHA }}" \ | jq '[.commits[]|{message:(.commit.message | split("\n")), username:.author.login}]' \ | jq -r '.[]|"- \(.message | first) (@\(.username))"') {delimiter}" >> $GITHUB_OUTPUT + - name: Prepare env + id: prepare_env + run: | + set -e + if [ "${{ github.event.inputs.git-ref }}" = "master" ]; then tag_prefix=r artifacts_prefix=standard/preview/app-standard @@ -85,7 +113,7 @@ jobs: id: set_changelog if: github.event.inputs.git-ref != 'master' run: | - changelog="$(git log ${{ steps.prepare_env.outputs.PREV_RELEASE_SHA }}..${{ steps.prepare_env.outputs.CURRENT_SHA }} --pretty=format:'{{changelogtext}}%s (@%an){{!changelogtext}}')" + changelog="$(git log ${{ steps.previous_commit.outputs.PREV_RELEASE_SHA }}..${{ steps.current_commit.outputs.CURRENT_SHA }} --pretty=format:'{{changelogtext}}%s (@%an){{!changelogtext}}')" changelog="${changelog//$'%'/%25}" changelog="${changelog//$'\n'/}" changelog="${changelog//$'\r'/}" @@ -94,7 +122,7 @@ jobs: changelog="${changelog//$'&'/}" changelog="$(echo $changelog | sed -e 's/{{changelogtext}}//g')" changelog="$(echo $changelog | sed -e 's/{{!changelogtext}}/<\/changelogtext>/g')" - changelog="$changelog" + changelog="$changelog" echo "CHANGELOG=$changelog" >> $GITHUB_OUTPUT build-app: