chore: update github actions, #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Cache Flutter App Version | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Read version from pubspec.yaml | |
id: read-version | |
run: | | |
echo "PREVIOUS_VERSION=$(grep 'version:' pubspec.yaml | awk '{print $2}')" >> $GITHUB_ENV | |
echo "UPDATED_VERSION=$(cat pubspec.yaml | grep 'version:' | awk '{print $2}')" >> $GITHUB_ENV | |
- name: Restore version from cache | |
id: cache | |
uses: actions/cache@v2 | |
with: | |
path: version | |
key: version-${{ env.PREVIOUS_VERSION }}-${{ env.UPDATED_VERSION }}-${{ runner.os }} | |
- name: Check if version is cached | |
run: | | |
if [ -f version/version.txt ]; then | |
echo "Version is cached: $(cat version/version.txt)" | |
else | |
echo "Version is not cached" | |
fi | |
- name: Increment updated version if necessary | |
run: | | |
if [ -f version/version.txt ]; then | |
cached_previous_version=$(grep 'previous_version:' version/version.txt | awk '{print $2}') | |
cached_updated_version=$(grep 'updated_version:' version/version.txt | awk '{print $2}') | |
if [ "${cached_previous_version}" == "${PREVIOUS_VERSION}" ]; then | |
IFS='+' read -r -a version_components <<< "${cached_updated_version}" | |
build_number=${version_components[-1]} | |
((build_number++)) | |
UPDATED_VERSION="${version_components[0]}+${build_number}" | |
echo "Updated version incremented to: ${UPDATED_VERSION}" | |
echo "UPDATED_VERSION=${UPDATED_VERSION}" >> $GITHUB_ENV | |
fi | |
fi | |
- name: Save version to cache | |
run: | | |
mkdir -p version | |
echo "previous_version: ${{ env.PREVIOUS_VERSION }}" > version/version.txt | |
echo "updated_version: ${{ env.UPDATED_VERSION }}" > version/version.txt | |
if: always() | |
# - name: Use cached version | |
# if: steps.cache.outputs.cache-hit == 'true' | |
# run: | | |
# echo "Using cached version: $(cat version/version.txt)" |