Skip to content

[XO-3014] Handle MDU API 422 error for unregistered shops #781

[XO-3014] Handle MDU API 422 error for unregistered shops

[XO-3014] Handle MDU API 422 error for unregistered shops #781

name: Build Module ZIPs - INT/PREPROD
on:
pull_request:
types: [edited, labeled, synchronize]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
generate-shared-date:
name: Generate shared date for all matrix jobs
runs-on: ubuntu-latest
if: |
contains(github.event.pull_request.labels.*.name, 'preproduction deployment') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle1') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle2') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle3') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle4') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle5') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle6') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle7') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle8') ||
contains(github.event.pull_request.labels.*.name, 'prestabulle9')
outputs:
shared_date: ${{ steps.date.outputs.date }}
steps:
- name: Generate shared date
id: date
run: |
date=$(date -d '+2 hours' +'%Y-%m-%d_%H-%M-%S')
echo "date=$date" >> $GITHUB_OUTPUT
prepare-zip:
needs: [generate-shared-date]
name: Prepare module ZIP artifacts
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
pull-requests: write
strategy:
fail-fast: false
matrix:
module:
- { dir: ps17, suffix: 7, php: '7.2' }
- { dir: ps8, suffix: 8, php: '8.1' }
- { dir: ps9, suffix: 9, php: '8.4' }
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Determine Environment
id: environment
env:
LABELS_JSON: ${{ toJSON(github.event.pull_request.labels) }}
run: |
# Get all labels as a JSON array and extract names
echo "Labels JSON: $LABELS_JSON"
# Extract label names using jq
LABEL_NAMES=$(echo "$LABELS_JSON" | jq -r '.[].name' | tr '\n' ' ')
# Check for integration labels (prestabulle1 through prestabulle9)
if echo "$LABEL_NAMES" | grep -q "prestabulle[1-9]"; then
echo "environment=integration" >> $GITHUB_OUTPUT
echo "provider_secret=WI_PROVIDER_V2_INTEGRATION" >> $GITHUB_OUTPUT
echo "sa_secret=WI_SA_V2_INTEGRATION" >> $GITHUB_OUTPUT
echo "gcp_project_secret=GCP_PROJECT_INTEGRATION" >> $GITHUB_OUTPUT
# Extract the specific prestabulle number
PRESTABULLE_LABEL=$(echo "$LABEL_NAMES" | grep -o "prestabulle[1-9]" | head -1)
echo "secret_name=module-v5-$PRESTABULLE_LABEL-env" >> $GITHUB_OUTPUT
echo "prestabulle_label=$PRESTABULLE_LABEL" >> $GITHUB_OUTPUT
echo "Detected integration environment with label: $PRESTABULLE_LABEL"
elif echo "$LABEL_NAMES" | grep -q "preproduction deployment"; then
echo "environment=preproduction" >> $GITHUB_OUTPUT
echo "provider_secret=WI_PROVIDER_V2_PREPRODUCTION" >> $GITHUB_OUTPUT
echo "sa_secret=WI_SA_V2_PREPRODUCTION" >> $GITHUB_OUTPUT
echo "gcp_project_secret=GCP_PROJECT_PREPRODUCTION" >> $GITHUB_OUTPUT
echo "secret_name=module-v5-env" >> $GITHUB_OUTPUT
echo "Detected preproduction environment"
else
echo "No matching labels found. Available labels: $LABEL_NAMES"
exit 1
fi
- name: Auth GCP 🔑
uses: ./.github/actions/auth-gcp
with:
provider: ${{ secrets[steps.environment.outputs.provider_secret] }}
service-account: ${{ secrets[steps.environment.outputs.sa_secret] }}
registry-login: true
setup-gcloud: true
- name: Write .env file 🌳
run: gcloud --quiet beta secrets versions access latest --project=$GCP_PROJECT --secret="$SECRET_NAME" > .env
env:
GCP_PROJECT: ${{ secrets[steps.environment.outputs.gcp_project_secret] }}
SECRET_NAME: ${{ steps.environment.outputs.secret_name }}
- name: Package module
id: package
uses: ./.github/actions/package-module
with:
module_dir: ${{ matrix.module.dir }}
module_suffix: ${{ matrix.module.suffix }}
php_version: ${{ matrix.module.php }}
release_filename: ps_checkout.${{ matrix.module.suffix }}.zip
- name: Generate GCP bucket filename
id: bucket-filename
run: |
# Use prestabulle label for integration, environment name for preproduction
if [[ "${{ steps.environment.outputs.environment }}" == "integration" ]]; then
ENV_LABEL="${{ steps.environment.outputs.prestabulle_label }}"
else
ENV_LABEL="${{ steps.environment.outputs.environment }}"
fi
echo "filename=pr${{ github.event.pull_request.number }}/ps_checkout-${{ matrix.module.suffix }}-$ENV_LABEL-${{ github.event.pull_request.number }}-${{ needs.generate-shared-date.outputs.shared_date }}.zip" >> $GITHUB_OUTPUT
- name: Upload directly to GCP bucket storage
run: |
gsutil cp "${{ steps.package.outputs.zip_path }}" \
gs://ps-eu-w1-checkout-assets-${{ steps.environment.outputs.environment }}/${{ steps.bucket-filename.outputs.filename }}