test #184
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: test | |
on: | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
jobs: | |
# job_id: | |
# runs-on: Linux | |
# permissions: | |
# contents: "read" | |
# id-token: "write" | |
# steps: | |
# - uses: "actions/checkout@v4" | |
# - uses: "google-github-actions/auth@v2" | |
# id: 'auth' | |
# with: | |
# project_id: ${{ secrets.GCP_PROJECT_ID }} | |
# workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} | |
# service_account: ${{ secrets.VIEWER_SERVICE_ACCOUNT }} | |
# - name: "Set up Cloud SDK" | |
# uses: "google-github-actions/setup-gcloud@v2" | |
# with: | |
# version: ">= 363.0.0" | |
# - run: | | |
# gcloud compute instances start opea-n4-16c-128g \ | |
# --project=${{ secrets.GCP_PROJECT_ID }} \ | |
# --zone=us-east1-d > /dev/null 2>&1 | |
# gcloud compute instances stop opea-n4-16c-128g \ | |
# --project=${{ secrets.GCP_PROJECT_ID }} \ | |
# --zone=us-east1-d | |
check-label-queue: | |
runs-on: Linux | |
steps: | |
- name: Get queued jobs with specific label | |
env: | |
GITHUB_TOKEN: ${{ secrets.ACTION_TOKEN }} | |
REPO_OWNER: ${{ github.repository_owner }} | |
REPO_NAME: ${{ github.event.repository.name }} | |
run: | | |
WORKFLOW_IDS=("test" "Probot") | |
QUEUED_JOBS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ | |
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runs?status=cancelled" | jq -r '.workflow_runs[] | .name') | |
RUNNING_JOBS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ | |
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runs?status=in_progress" | jq -r '.workflow_runs[] | .name') | |
queued_count=0 | |
for name in $QUEUED_JOBS; do | |
if printf "%s\n" "${WORKFLOW_IDS[@]}" | grep -qx "$name"; then | |
queued_count=$((queued_count + 1)) | |
fi | |
done | |
running_count=0 | |
for name in $RUNNING_JOBS; do | |
if printf "%s\n" "${WORKFLOW_IDS[@]}" | grep -qx "$name"; then | |
running_count=$((running_count + 1)) | |
fi | |
done | |
echo "There are $queued_count queued jobs and $running_count running jobs." | |
if [[ $queued_count > 0 ]] || [[ $running_count > 1 ]]; then | |
exit 1 | |
fi |