File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Variables
4+ source .env
5+ REPO=" $REPO " # Repository from .env
6+ TOKEN=" $TOKEN " # GitHub token from .env
7+ OUTPUT_DIR=" $OUTPUT_DIR " # Output directory from .env
8+
9+ # Get the latest workflow run ID
10+ LATEST_RUN_ID=$( curl -s -H " Authorization: token $TOKEN " \
11+ " https://api.github.com/repos/$REPO /actions/runs?per_page=1" | \
12+ jq -r ' .workflow_runs[0].id' )
13+
14+ if [ -z " $LATEST_RUN_ID " ] || [ " $LATEST_RUN_ID " == " null" ]; then
15+ echo " Error: Unable to fetch the latest workflow run ID. Check your repository and token."
16+ exit 1
17+ fi
18+
19+ # Get the artifact download URL
20+ ARTIFACT_URL=$( curl -s -H " Authorization: token $TOKEN " \
21+ " https://api.github.com/repos/$REPO /actions/runs/$LATEST_RUN_ID /artifacts" | \
22+ jq -r ' .artifacts[0].archive_download_url' )
23+
24+ if [ -z " $ARTIFACT_URL " ] || [ " $ARTIFACT_URL " == " null" ]; then
25+ echo " Error: Unable to fetch the artifact download URL. Check if artifacts are available."
26+ exit 1
27+ fi
28+
29+ # Download the artifact
30+ curl -L -H " Authorization: token $TOKEN " \
31+ -o " $OUTPUT_DIR /latest_artifact.zip" " $ARTIFACT_URL "
32+
33+ if [ $? -ne 0 ]; then
34+ echo " Error: Failed to download the artifact."
35+ exit 1
36+ fi
37+
38+ echo " Artifact downloaded to $OUTPUT_DIR /latest_artifact.zip"
39+
40+ # Extract the artifact and overwrite any existing files
41+ unzip -o " $OUTPUT_DIR /latest_artifact.zip" -d " $OUTPUT_DIR "
42+
43+ if [ $? -ne 0 ]; then
44+ echo " Error: Failed to extract the artifact."
45+ exit 1
46+ fi
You can’t perform that action at this time.
0 commit comments