Skip to content

Commit

Permalink
Introduce alternative way of caching JAR files (#204)
Browse files Browse the repository at this point in the history
* Introduce alternative way of caching JAR files

* Check rev hash file being downloaded

* Check calc checksum output

* Fix release tag set
  • Loading branch information
4ernovm authored Feb 23, 2024
1 parent 698d30c commit 2a4dc25
Showing 1 changed file with 42 additions and 11 deletions.
53 changes: 42 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,74 @@ jobs:

- name: Calculate checksum
id: calc-checksum
run: echo "hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
run: |
TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name')
curl -LJO https://github.com/${{ github.repository }}/releases/download/${TAG}/soot-wrapper-rev-hash.txt
echo "release_tag=$TAG" >> $GITHUB_OUTPUT
echo "hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
if [ ! -f soot-wrapper-rev-hash.txt ]; then
touch soot-wrapper-rev-hash.txt
fi
echo "prev_hash=$(cat soot-wrapper-rev-hash.txt)" >> $GITHUB_OUTPUT
- name: Pull JAR from previous release if already built
if: steps.calc-checksum.outputs.hash == steps.calc-checksum.outputs.prev_hash
run: |
curl -LJO https://github.com/${{ github.repository }}/releases/download/${{ steps.calc-checksum.outputs.release_tag }}/soot-wrapper-${{ matrix.java-version }}.jar
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Cache JARs
uses: actions/cache@v4
id: cache-jars
- name: Upload JAR from previous release
if: steps.calc-checksum.outputs.hash == steps.calc-checksum.outputs.prev_hash
uses: actions/upload-artifact@v4
with:
path: |
java/common/target/*.jar
key: ${{ runner.os }}-soot-wrapper-${{ matrix.java-version }}-${{ steps.calc-checksum.outputs.hash }}
name: soot-wrapper-${{ matrix.java-version }}.jar
path: soot-wrapper-${{ matrix.java-version }}.jar

- name: Set up JDK ${{ matrix.java-version }}
if: steps.cache-jars.outputs.cache-hit != 'true'
if: steps.calc-checksum.outputs.hash != steps.calc-checksum.outputs.prev_hash
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'adopt'

- name: Build with Maven
if: steps.cache-jars.outputs.cache-hit != 'true'
if: steps.calc-checksum.outputs.hash != steps.calc-checksum.outputs.prev_hash
run: |
cd java/common/
mvn clean package -X -DskipTests
- name: Upload JAR if cache missed
if: steps.cache-jars.outputs.cache-hit != 'true'
- name: Upload generated JAR
if: steps.calc-checksum.outputs.hash != steps.calc-checksum.outputs.prev_hash
uses: actions/upload-artifact@v4
with:
name: soot-wrapper-${{ matrix.java-version }}.jar
path: java/common/target/*.jar

- name: Store soot-wrapper revision hash
if: steps.calc-checksum.outputs.hash != steps.calc-checksum.outputs.prev_hash
run: |
echo ${{ steps.calc-checksum.outputs.hash }} > soot-wrapper-rev-hash.txt
- name: Upload file containing soot-wrapper revision hash
if: steps.calc-checksum.outputs.hash != steps.calc-checksum.outputs.prev_hash
uses: actions/upload-artifact@v4
with:
name: soot-wrapper-rev-hash.txt
path: soot-wrapper-rev-hash.txt
overwrite: 'true'

goreleaser:
runs-on: ubuntu-latest
needs: soot-wrapper
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- run: git fetch --force --tags

- uses: actions/setup-go@v5
with:
go-version: '>=1.20'
Expand Down Expand Up @@ -94,6 +124,7 @@ jobs:
with:
tag_name: ${{ github.ref_name }}
files: |
/home/runner/work/cli/cli/soot-wrapper-rev-hash.txt
/home/runner/work/cli/cli/soot-wrapper-11.jar
/home/runner/work/cli/cli/soot-wrapper-17.jar
/home/runner/work/cli/cli/soot-wrapper-21.jar
Expand Down

0 comments on commit 2a4dc25

Please sign in to comment.