Skip to content

Commit

Permalink
Improve:
Browse files Browse the repository at this point in the history
- Condition to run only when provide git-ref
- Split prepare_env steps
- More log
- Fake commit_count_diff when there is no changes
  • Loading branch information
cuong-tran committed May 10, 2024
1 parent 4583107 commit 86b2ea0
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions .github/workflows/build_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand All @@ -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'/}"
Expand All @@ -94,7 +122,7 @@ jobs:
changelog="${changelog//$'&'/}"
changelog="$(echo $changelog | sed -e 's/{{changelogtext}}/<changelogtext>/g')"
changelog="$(echo $changelog | sed -e 's/{{!changelogtext}}/<\/changelogtext>/g')"
changelog="<?xml version=\"1.0\" encoding=\"utf-8\"?><changelog bulletedList=\"true\"><changelogversion versionName=\"${{ github.run_number }}\" changeDate=\"\">$changelog</changelogversion></changelog>"
changelog="<?xml version=\"1.0\" encoding=\"utf-8\"?><changelog bulletedList=\"true\"><changelogversion versionName=\"${{ steps.current_commit.outputs.COMMIT_COUNT }}\" changeDate=\"\">$changelog</changelogversion></changelog>"
echo "CHANGELOG=$changelog" >> $GITHUB_OUTPUT
build-app:
Expand Down

0 comments on commit 86b2ea0

Please sign in to comment.