Modular logistics and supply chain operating system (LSOS)
JavaScript driver-appfleet-managementfreight-managementinfrastructureinventory-managementlast-mile-deliverylogisticsondemandopen-sourceorder-managementroute-optimizationsupply-chain-managementtracking-and-monitoringtransport-management-systemtransportationwarehouse-management
fix(ci): enforce cloud promotion paths safely
Ronald A. Richardson86edf8002c94
diff --git a/.github/workflows/cloud.yml b/.github/workflows/cloud.ymlindex 55f6b481..2f9d788d 100644--- a/.github/workflows/cloud.yml+++ b/.github/workflows/cloud.yml@@ -1,21 +1,64 @@-name: "Close Invalid PRs"+name: "Enforce Cloud Promotion PRs"on:- pull_request:+ pull_request_target:+ types: [opened, reopened, synchronize, edited]branches:- cloud+ - cloud-qa++permissions:+ contents: read+ pull-requests: writejobs:- close_pr:+ enforce_promotion_path:runs-on: ubuntu-latest+ timeout-minutes: 5steps:- - name: Close invalid PRs+ - name: Validate promotion pathenv:- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ GH_TOKEN: ${{ github.token }}+ PR_BASE_REF: ${{ github.event.pull_request.base.ref }}PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}+ PR_HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}PR_NUMBER: ${{ github.event.pull_request.number }}- REPO: ${{ github.repository }}+ REPOSITORY: ${{ github.repository }}run: |- if [[ "$PR_HEAD_REF" != "main" ]] && [[ "$PR_HEAD_REF" != "dev-cloud" ]]; then- echo "This PR is from '$PR_HEAD_REF', but only PRs from 'main' or 'dev-cloud' are allowed. Closing PR."- gh pr close "$PR_NUMBER" --repo "$REPO"+ set -euo pipefail++ allowed=false++ if [[ "$PR_HEAD_REPOSITORY" == "$REPOSITORY" ]]; then+ case "$PR_BASE_REF" in+ cloud-qa)+ if [[ "$PR_HEAD_REF" == "main" ]]; then+ allowed=true+ fi+ ;;+ cloud)+ if [[ "$PR_HEAD_REF" == "cloud-qa" || "$PR_HEAD_REF" == "main" ]]; then+ allowed=true+ fi+ ;;+ esacfi++ if [[ "$allowed" == "true" ]]; then+ echo "Allowed promotion: $PR_HEAD_REPOSITORY:$PR_HEAD_REF -> $PR_BASE_REF"+ exit 0+ fi++ case "$PR_BASE_REF" in+ cloud-qa)+ message="This pull request was closed because cloud-qa only accepts promotions from the main branch in the fleetbase/fleetbase repository."+ ;;+ cloud)+ message="This pull request was closed because cloud only accepts promotions from the cloud-qa branch, or emergency promotions from main, in the fleetbase/fleetbase repository."+ ;;+ *)+ message="This pull request was closed because it does not follow the Fleetbase cloud promotion path."+ ;;+ esac++ gh pr comment "$PR_NUMBER" --repo "$REPOSITORY" --body "$message"+ gh pr close "$PR_NUMBER" --repo "$REPOSITORY"