Download and Process Artifacts #53
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: Download and Process Artifacts | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs at 00:00 UTC daily | |
workflow_dispatch: # Allows manual triggering of the workflow | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up jq | |
run: sudo apt-get install jq | |
- name: Download and Process Artifacts from GitLab | |
env: | |
ACCESS_TOKEN: ${{ secrets.GITLAB_ACCESS_TOKEN }} | |
PROJECT_ID: xen-project%2Fxen-guest-agent | |
JOB_NAME: build-release-linux-x86_64 | |
run: | | |
set -e | |
JOBS_API="https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs?scope[]=success" | |
echo "Fetching job list from $JOBS_API" | |
JOBS_RESPONSE=$(curl --silent --header "PRIVATE-TOKEN: $ACCESS_TOKEN" "$JOBS_API") | |
LATEST_JOB_ID=$(echo "$JOBS_RESPONSE" | jq -r "[.[] | select(.name==\"$JOB_NAME\" and .status==\"success\") | {id: .id, created_at: .created_at}] | sort_by(.created_at) | last | .id") | |
if [ -z "$LATEST_JOB_ID" ] || [ "$LATEST_JOB_ID" == "null" ]; then | |
echo "No valid job found. Exiting." | |
exit 1 | |
fi | |
echo "Found latest successful job ID: $LATEST_JOB_ID" | |
ARTIFACTS_API="https://gitlab.com/api/v4/projects/$PROJECT_ID/jobs/$LATEST_JOB_ID/artifacts" | |
echo "Downloading artifacts from $ARTIFACTS_API" | |
curl -L --header "PRIVATE-TOKEN: $ACCESS_TOKEN" "$ARTIFACTS_API" --output artifacts.zip | |
echo "Artifacts downloaded as artifacts.zip" | |
# Unzip artifacts.zip to get xen-guest-agent | |
unzip artifacts.zip -d extracted-artifacts | |
mkdir -p usr/sbin | |
mv extracted-artifacts/target/release/xen-guest-agent usr/sbin/ | |
chmod +x usr/sbin/xen-guest-agent | |
# Process for CoreOS | |
mkdir -p xen-guest-agent-coreos/usr | |
cp -r usr/* xen-guest-agent-coreos/usr/ | |
rm -f xen-guest-agent-coreos/usr/lib/extension-release.d/extension-release.flatcar-linux | |
mv xen-guest-agent-coreos/usr/lib/extension-release.d/extension-release.coreos xen-guest-agent-coreos/usr/lib/extension-release.d/extension-release.xen-guest-agent | |
mksquashfs xen-guest-agent-coreos xen-guest-agent-coreos.raw -noappend | |
echo "CoreOS squashfs created" | |
# Process for Flatcar | |
mkdir -p xen-guest-agent-flatcar/usr | |
cp -r usr/* xen-guest-agent-flatcar/usr/ | |
rm -f xen-guest-agent-flatcar/usr/lib/extension-release.d/extension-release.coreos | |
mv xen-guest-agent-flatcar/usr/lib/extension-release.d/extension-release.flatcar-linux xen-guest-agent-flatcar/usr/lib/extension-release.d/extension-release.xen-guest-agent | |
mksquashfs xen-guest-agent-flatcar xen-guest-agent-flatcar.raw -noappend | |
echo "Flatcar squashfs created" | |
- name: Upload CoreOS Squashfs as Artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: xen-guest-agent-coreos | |
path: xen-guest-agent-coreos.raw | |
- name: Upload Flatcar Squashfs as Artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: xen-guest-agent-flatcar | |
path: xen-guest-agent-flatcar.raw |