[#37] Implement session level caching of PropertyProvider values #3
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: GH Actions CI | |
on: | |
push: | |
branches: | |
- 'main' | |
pull_request: | |
branches: | |
- 'main' | |
permissions: { } # none | |
concurrency: | |
# Consider that two builds are in the same concurrency group (cannot run concurrently) | |
# if they use the same workflow and are about the same branch ("ref") or pull request. | |
group: "workflow = ${{ github.workflow }}, ref = ${{ github.event.ref }}, pr = ${{ github.event.pull_request.id }}" | |
# Cancel previous builds in the same concurrency group even if they are in progress | |
# for pull requests or pushes to forks (not the upstream repository). | |
cancel-in-progress: ${{ github.event_name == 'pull_request' || github.repository != 'Blazebit/blaze-query' }} | |
jobs: | |
build: | |
permissions: | |
contents: read | |
name: OpenJDK 17 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- name: Set up Java 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: Generate cache key | |
id: cache-key | |
run: | | |
CURRENT_BRANCH="${{ github.repository != 'Blazebit/blaze-query' && 'fork' || github.base_ref || github.ref_name }}" | |
CURRENT_MONTH=$(/bin/date -u "+%Y-%m") | |
CURRENT_DAY=$(/bin/date -u "+%d") | |
ROOT_CACHE_KEY="buildtool-cache" | |
echo "buildtool-monthly-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}" >> $GITHUB_OUTPUT | |
echo "buildtool-monthly-branch-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}" >> $GITHUB_OUTPUT | |
echo "buildtool-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}-${CURRENT_DAY}" >> $GITHUB_OUTPUT | |
- name: Cache Maven/Gradle Dependency/Dist Caches | |
id: cache-maven | |
uses: actions/cache@v4 | |
# if it's not a pull request, we restore and save the cache | |
if: github.event_name != 'pull_request' | |
with: | |
path: | | |
~/.m2/repository/ | |
~/.m2/wrapper/ | |
~/.gradle/caches/modules-2 | |
~/.gradle/wrapper/ | |
# A new cache will be stored daily. After that first store of the day, cache save actions will fail because the cache is immutable but it's not a problem. | |
# The whole cache is dropped monthly to prevent unlimited growth. | |
# The cache is per branch but in case we don't find a branch for a given branch, we will get a cache from another branch. | |
key: ${{ steps.cache-key.outputs.buildtool-cache-key }} | |
restore-keys: | | |
${{ steps.cache-key.outputs.buildtool-monthly-branch-cache-key }}- | |
${{ steps.cache-key.outputs.buildtool-monthly-cache-key }}- | |
- name: Restore Maven/Gradle Dependency/Dist Caches | |
uses: actions/cache/restore@v4 | |
# if it a pull request, we restore the cache but we don't save it | |
if: github.event_name == 'pull_request' | |
with: | |
path: | | |
~/.m2/repository/ | |
~/.m2/wrapper/ | |
~/.gradle/caches/modules-2 | |
~/.gradle/wrapper/ | |
key: ${{ steps.cache-key.outputs.buildtool-cache-key }} | |
restore-keys: | | |
${{ steps.cache-key.outputs.buildtool-monthly-branch-cache-key }}- | |
${{ steps.cache-key.outputs.buildtool-monthly-cache-key }}- | |
- name: Run build script | |
run: ./ci/build-github.sh | |
shell: bash | |
- name: Upload test reports (if Gradle failed) | |
uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: test-reports-java17 | |
path: | | |
./**/target/reports/tests/ | |
- name: Omit produced artifacts from build cache | |
run: ./ci/before-cache.sh | |
# Static code analysis check | |
format_checks: | |
permissions: | |
contents: read | |
name: Static code analysis | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- name: Set up Java 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: Generate cache key | |
id: cache-key | |
run: | | |
CURRENT_BRANCH="${{ github.repository != 'Blazebit/blaze-query' && 'fork' || github.base_ref || github.ref_name }}" | |
CURRENT_MONTH=$(/bin/date -u "+%Y-%m") | |
CURRENT_DAY=$(/bin/date -u "+%d") | |
ROOT_CACHE_KEY="buildtool-cache-format" | |
echo "buildtool-monthly-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}" >> $GITHUB_OUTPUT | |
echo "buildtool-monthly-branch-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}" >> $GITHUB_OUTPUT | |
echo "buildtool-cache-key=${ROOT_CACHE_KEY}-${CURRENT_MONTH}-${CURRENT_BRANCH}-${CURRENT_DAY}" >> $GITHUB_OUTPUT | |
- name: Cache Maven/Gradle Dependency/Dist Caches | |
id: cache-maven | |
uses: actions/cache@v4 | |
# if it's not a pull request, we restore and save the cache | |
if: github.event_name != 'pull_request' | |
with: | |
path: | | |
~/.m2/repository/ | |
~/.m2/wrapper/ | |
~/.gradle/caches/modules-2 | |
~/.gradle/wrapper/ | |
# A new cache will be stored daily. After that first store of the day, cache save actions will fail because the cache is immutable but it's not a problem. | |
# The whole cache is dropped monthly to prevent unlimited growth. | |
# The cache is per branch but in case we don't find a branch for a given branch, we will get a cache from another branch. | |
key: ${{ steps.cache-key.outputs.buildtool-cache-key }} | |
restore-keys: | | |
${{ steps.cache-key.outputs.buildtool-monthly-branch-cache-key }}- | |
${{ steps.cache-key.outputs.buildtool-monthly-cache-key }}- | |
- name: Restore Maven/Gradle Dependency/Dist Caches | |
uses: actions/cache/restore@v4 | |
# if it a pull request, we restore the cache but we don't save it | |
if: github.event_name == 'pull_request' | |
with: | |
path: | | |
~/.m2/repository/ | |
~/.m2/wrapper/ | |
~/.gradle/caches/modules-2 | |
~/.gradle/wrapper/ | |
key: ${{ steps.cache-key.outputs.buildtool-cache-key }} | |
restore-keys: | | |
${{ steps.cache-key.outputs.buildtool-monthly-branch-cache-key }}- | |
${{ steps.cache-key.outputs.buildtool-monthly-cache-key }}- | |
- name: Run build script | |
run: ./gradlew formatChecks | |
- name: Upload test reports (if Gradle failed) | |
uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: test-reports-java17 | |
path: | | |
./**/target/reports/tests/ | |
- name: Omit produced artifacts from build cache | |
run: ./ci/before-cache.sh |