chore: update package information #94
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: E2E Linux (Google Cloud) | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
linux-e2e: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
fs: ['btrfs', 'xfs'] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Authenticate with Google Cloud | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: ${{ secrets.GCP_CREDENTIALS }} | |
- name: Setup GCP environment | |
uses: google-github-actions/setup-gcloud@v1 | |
- name: Generate random instance and disk name | |
run: | | |
INSTANCE_UUID=$(uuidgen | cut -d '-' -f1) | |
INSTANCE_NAME="vm-$INSTANCE_UUID" | |
DISK_NAME="$INSTANCE_NAME-disk" | |
echo "INSTANCE_NAME=$INSTANCE_NAME" >> $GITHUB_ENV | |
echo "DISK_NAME=$DISK_NAME" >> $GITHUB_ENV | |
- name: Get current repo name | |
run: | | |
REPO_NAME=$(basename $(git rev-parse --show-toplevel)) | |
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV | |
- name: Set default project | |
run: | | |
gcloud config set project ${{ secrets.GCP_PROJECT_ID }} | |
- name: Generate SSH key pair | |
run: | | |
ssh-keygen -t rsa -b 4096 -f ./gcloud -C "${{ secrets.GCP_MAIL }}" -N "" | |
- name: Fetch available zones and set dynamic zone | |
run: | | |
sudo apt-get install -y jq | |
AVAILABLE_ZONES=$(gcloud compute zones list --project=${{ secrets.GCP_PROJECT_ID }} --format="value(name)") | |
for ZONE in $AVAILABLE_ZONES; do | |
REGION=$(echo $ZONE | sed 's/\([a-z]*-[a-z]*[1-9]\)-[a-z]*/\1/') | |
QUOTAS_JSON=$(gcloud compute regions describe $REGION --project=${{ secrets.GCP_PROJECT_ID }} --format=json) | |
SSD_QUOTA=$(echo $QUOTAS_JSON | jq '.quotas[] | select(.metric == "SSD_TOTAL_GB") | .limit') | |
if (( $(echo "$SSD_QUOTA >= 40" | bc -l) )); then | |
echo "Selected Zone: $ZONE" | |
echo "ZONE=$ZONE" >> $GITHUB_ENV | |
break | |
fi | |
done | |
- name: Create GCP VM with Spot provisioning | |
run: | | |
gcloud compute instances create $INSTANCE_NAME \ | |
--project=${{ secrets.GCP_PROJECT_ID }} \ | |
--zone=${{ env.ZONE }} \ | |
--machine-type=e2-small \ | |
--source-machine-image=linux-rs \ | |
--no-restart-on-failure \ | |
--maintenance-policy=TERMINATE \ | |
--provisioning-model=SPOT \ | |
--instance-termination-action=DELETE \ | |
--service-account=${{ secrets.GCP_SERVICE_ACCOUNT }} \ | |
--create-disk=size=10GB,device-name=$DISK_NAME,mode=rw,type=projects/${{ secrets.GCP_PROJECT_ID }}/zones/${{ env.ZONE }}/diskTypes/pd-balanced \ | |
--metadata ssh-keys="${{ secrets.GCP_USER }}:$(cat ./gcloud.pub)" | |
- name: Wait for VM to be ready | |
run: | | |
for i in {1..30}; do | |
if gcloud compute ssh $INSTANCE_NAME --command="echo ready" --zone=${{ env.ZONE }} --ssh-key-file=./gcloud; then | |
break | |
else | |
echo "Retrying ($i)..." | |
sleep 2 | |
fi | |
done | |
- name: Run init script | |
run: | | |
SCRIPT_PATH=scripts/linux-${{ matrix.fs }}.sh | |
SCRIPT_CONTENT=$(cat $SCRIPT_PATH) | |
gcloud compute ssh $INSTANCE_NAME --zone=${{ env.ZONE }} \ | |
--ssh-key-file=./gcloud \ | |
--command="echo '$SCRIPT_CONTENT' > init-script.sh && chmod +x init-script.sh && ./init-script.sh" | |
- name: Copy Repo to GCP VM | |
run: | | |
gcloud compute scp --recurse ../${{ env.REPO_NAME }} ${{ secrets.GCP_USER }}@$INSTANCE_NAME:/mnt/${{ matrix.fs }}/code --zone=${{ env.ZONE }} --ssh-key-file=./gcloud | |
- name: List files on VM | |
run: | | |
gcloud compute ssh ${{ secrets.GCP_USER }}@$INSTANCE_NAME --zone=${{ env.ZONE }} \ | |
--ssh-key-file=./gcloud \ | |
--command="ls -la /mnt/${{ matrix.fs }}/code/${{ env.REPO_NAME }}" | |
- name: Run Tests | |
run: | | |
gcloud compute ssh ${{ secrets.GCP_USER }}@$INSTANCE_NAME --zone=${{ env.ZONE }} \ | |
--ssh-key-file=./gcloud \ | |
--command="export PATH=\$PATH:~/.cargo/bin && cd /mnt/${{ matrix.fs }}/code/${{ env.REPO_NAME }} && cargo test" | |
# Cleanup | |
- name: Delete GCP VM if exists | |
if: always() | |
run: | | |
if gcloud compute instances describe $INSTANCE_NAME --zone=${{ env.ZONE }} > /dev/null 2>&1; then | |
gcloud compute instances delete $INSTANCE_NAME --zone=${{ env.ZONE }} --quiet | |
else | |
echo "VM does not exist. Skipping deletion." | |
fi | |
- name: Delete GCP Disk if exists | |
if: always() | |
run: | | |
if gcloud compute disks describe $DISK_NAME --zone=${{ env.ZONE }} > /dev/null 2>&1; then | |
gcloud compute disks delete $DISK_NAME --zone=${{ env.ZONE }} --quiet | |
else | |
echo "Disk does not exist. Skipping deletion." | |
fi |