Skip to content

Commit

Permalink
use cache method for build revision
Browse files Browse the repository at this point in the history
  • Loading branch information
RaidMax committed Jun 30, 2024
1 parent 57143b1 commit a24aaf1
Showing 1 changed file with 63 additions and 7 deletions.
70 changes: 63 additions & 7 deletions .github/workflows/build_application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,74 @@ env:
releaseType: prerelease

jobs:
make_version:
update_revision_number:
runs-on: ubuntu-latest

outputs:
build_num: ${{ steps.generate_build_number.outputs.build_num }}
revision_number: ${{ steps.revision.outputs.revision_number }}

steps:
- name: Checkout code
- name: Checkout repository
uses: actions/checkout@v4


- name: Restore cache
id: cache
uses: actions/cache@v2
with:
path: cache_dir
key: revision-number

- name: Get current date
id: date
run: echo "current_date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV

- name: Check and update revision number
id: revision
run: |
FILENAME=cache_dir/revision_number.txt
DATEFILE=cache_dir/previous_date.txt
mkdir -p cache_dir
if [ -f "$DATEFILE" ]; then
prev_date=$(cat "$DATEFILE")
rev_number=$(cat "$FILENAME")
else
prev_date=""
rev_number=0
fi
if [ "$current_date" = "$prev_date" ]; then
rev_number=$((rev_number + 1))
else
rev_number=1
fi
echo "New revision number: $rev_number"
echo $rev_number > "$FILENAME"
echo $current_date > "$DATEFILE"
echo "revision_number=$rev_number" >> $GITHUB_OUTPUT
- name: Save cache
uses: actions/cache@v2
with:
path: cache_dir
key: revision-number

make_version:
runs-on: ubuntu-latest
needs: [ update_revision_number ]

outputs:
build_num: ${{ steps.generate_build_number.outputs.build_num }}
env:
revisionNumber: ${{ needs.update_revision_number.outputs.revision_number }}

steps:
- name: Make build number
id: generate_build_number
run: |
today=$(date +%Y-%m-%d)
commit_count=$(git rev-list --count --since="$today 00:00:00" --until="$today 23:59:59")
build_num=$(date +'%Y.%-m.%-d').$(commit_count)
build_num=$(date +'%Y.%-m.%-d').${{ env.revisionNumber }}
echo "build_num=$build_num" >> $GITHUB_OUTPUT
echo "Build number is $build_num"
Expand All @@ -55,6 +108,9 @@ jobs:
buildNumber: ${{ needs.make_version.outputs.build_num }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
Expand Down

0 comments on commit a24aaf1

Please sign in to comment.