Skip to content

Commit

Permalink
by run ID
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacbrodsky committed Jan 30, 2023
1 parent 78229d9 commit 39e626a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ jobs:
- name: Download and test
run: |
mvn clean test -Dh3.github.artifacts.use=true -Dh3.github.artifacts.ref=${{ github.sha }}
mvn clean test -Dh3.github.artifacts.use=true -Dh3.github.artifacts.by_run=${{ github.run_id }}
env:
GH_TOKEN: ${{ github.token }}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<h3.system.prune>false</h3.system.prune>
<h3.dockcross.tag>20210624-de7b1b0</h3.dockcross.tag>
<h3.github.artifacts.use>false</h3.github.artifacts.use>
<h3.github.artifacts.ref />
<h3.github.artifacts.by_run />
<!-- Used for passing additional arguments to surefire when using JaCoCo -->
<h3.additional.argLine />

Expand Down Expand Up @@ -271,7 +271,7 @@
<argument>${h3.system.prune}</argument>
<argument>${h3.dockcross.tag}</argument>
<argument>${h3.github.artifacts.use}</argument>
<argument>${h3.github.artifacts.ref}</argument>
<argument>${h3.github.artifacts.by_run}</argument>
</arguments>
</configuration>
</execution>
Expand Down
6 changes: 3 additions & 3 deletions src/main/c/h3-java/build-h3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# github-artifacts - When set, all build artifacts are retrieved from Github
# Actions artifacts rather than built locally (overrides
# all other settings.)
# github-artifacts-ref - When set, override the default revision to pull artifacts from
# github-artifacts-run - When set, override the default revision to pull artifacts from
# for `github-artifacts`.
#
# This script downloads H3, builds H3 and the H3-Java native library, and
Expand All @@ -45,10 +45,10 @@ USE_DOCKER=$3
SYSTEM_PRUNE=$4
DOCKCROSS_TAG=$5
GITHUB_ARTIFACTS=$6
GITHUB_ARTIFACTS_REF=$7
GITHUB_ARTIFACTS_RUN=$7

if $GITHUB_ARTIFACTS; then
src/main/c/h3-java/pull-from-github.sh "$GITHUB_ARTIFACTS_REF"
src/main/c/h3-java/pull-from-github.sh "$GITHUB_ARTIFACTS_RUN"
# The build of the library below is still needed for the binding-functions file
fi

Expand Down
25 changes: 14 additions & 11 deletions src/main/c/h3-java/pull-from-github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@

set -eox pipefail

GITHUB_ARTIFACTS_REF=$1
GITHUB_ARTIFACTS_RUN=$1

if [ -z "$GITHUB_ARTIFACTS_REF" ]; then
GIT_REVISION=$(git rev-parse HEAD)
else
GIT_REVISION="$GITHUB_ARTIFACTS_REF"
fi
EXTRACT_TO=src/main/resources

echo downloading artifacts for $GIT_REVISION

mkdir -p target
pushd target

TO_DOWNLOAD=$(gh api \
ARTIFACTS_LIST=$(gh api \
-H "Accept: application/vnd.github+json" \
/repos/{owner}/{repo}/actions/artifacts \
| jq ".artifacts[] | select(.workflow_run.head_sha == \"$GIT_REVISION\")")
/repos/{owner}/{repo}/actions/artifacts)

if [ -z "$GITHUB_ARTIFACTS_RUN" ]; then
GIT_REVISION=$(git rev-parse HEAD)
echo "downloading artifacts for sha $GIT_REVISION"
TO_DOWNLOAD=$(echo "$ARTIFACTS_LIST" \
| jq ".artifacts[] | select(.workflow_run.head_sha == \"$GIT_REVISION\")")
else
echo "downloading artifacts for run $GITHUB_ARTIFACTS_RUN"
TO_DOWNLOAD=$(echo "$ARTIFACTS_LIST" \
| jq ".artifacts[] | select(.workflow_run.id == \"$GITHUB_ARTIFACTS_RUN\")")
fi

echo $TO_DOWNLOAD | jq -c '.' | while read artifactline; do
ARTIFACT_NAME=$(echo $artifactline | jq -r .name)
Expand Down

0 comments on commit 39e626a

Please sign in to comment.