PLAYRTS-5538 Update RTS AppStore screenshots workflow #63
Workflow file for this run
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: Deployments after PR closure | |
on: | |
pull_request: | |
types: [closed] | |
jobs: | |
update-deployment: | |
runs-on: ubuntu-latest | |
permissions: | |
deployments: write | |
steps: | |
- name: Update deployment statuses to Inactive | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
GITHUB_REPOSITORY: ${{ github.repository }} | |
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} | |
run: | | |
AUTHORIZATION="Authorization: token $GITHUB_TOKEN" | |
ACCEPT="Accept: application/vnd.github.ant-man-preview+json" | |
PR_URL="https://api.github.com/repos/$GITHUB_REPOSITORY/pulls/$GITHUB_PR_NUMBER" | |
DEPLOYMENTS_URL="https://api.github.com/repos/$GITHUB_REPOSITORY/deployments" | |
echo "Working with PR URL: $PR_URL" | |
# Get the pull request head branch | |
HEAD_BRANCH=$(curl -s -H "$AUTHORIZATION" "$PR_URL" | jq -r '.head.ref') | |
if [ "$HEAD_BRANCH" == "null" ]; then | |
echo "No PR available, so no founded environments. Exiting..." | |
exit 0 | |
fi | |
# Get the pull request state | |
PR_STATE=$(curl -s -H "$AUTHORIZATION" "$PR_URL" | jq -r '.state') | |
if [ "$PR_STATE" != "closed" ]; then | |
echo "PR not closed. Exiting..." | |
exit 0 | |
fi | |
# Remove "feature/" from the head branch | |
BUILD_NAME=$(echo "$HEAD_BRANCH" | sed 's/feature\///g') | |
# Function to fetch log and environment URLs from status URL | |
fetch_status_urls() { | |
STATUS_URL=$1 | |
STATUS_RESPONSE=$(curl -s -H "$AUTHORIZATION" "$STATUS_URL") | |
FIRST_STATUS=$(echo "$STATUS_RESPONSE" | jq -r '.[0]') | |
LOG_URL=$(echo "$FIRST_STATUS" | jq -r '.log_url') | |
ENVIRONMENT_URL=$(echo "$FIRST_STATUS" | jq -r '.environment_url') | |
echo "$LOG_URL,$ENVIRONMENT_URL" | |
} | |
# Function to set inactive state to the latest deployment | |
set_inactive_latest_deployment() { | |
local ENVIRONMENT=$1 | |
local ENVIRONMENT_ENCODED=$(echo "$ENVIRONMENT" | jq -R -r @uri) | |
# Get the latest active deployment | |
local DEPLOYMENTS_FULL_URL="$DEPLOYMENTS_URL?environment=$ENVIRONMENT_ENCODED" | |
local DEPLOYMENT_DATA=$(curl -s -H "$AUTHORIZATION" "$DEPLOYMENTS_FULL_URL" | jq '.[0]') | |
if [ "$DEPLOYMENT_DATA" != "null" ]; then | |
local DEPLOYMENT_ID=$(echo "$DEPLOYMENT_DATA" | jq -r '.id') | |
local STATUSES_URL=$(echo "$DEPLOYMENT_DATA" | jq -r '.statuses_url') | |
echo "Working with $ENVIRONMENT deployment ID: $DEPLOYMENT_ID" | |
local URLS=$(fetch_status_urls "$STATUSES_URL") | |
IFS=',' read -r LOG_URL ENVIRONMENT_URL <<< "$URLS" | |
# Mark the latest deployment as inactive | |
local DEPLOYMENT_URL="$DEPLOYMENTS_URL/$DEPLOYMENT_ID/statuses" | |
local BODY="{\"state\": \"inactive\", \"description\": \"The PR is closed.\", \ | |
\"log_url\": \"$LOG_URL\", \"environment_url\": \"$ENVIRONMENT_URL\"}" | |
local RESPONSE=$(curl -s -X POST -H "$AUTHORIZATION" -H "$ACCEPT" "$DEPLOYMENT_URL" -d "$BODY") | |
# Extract information from the response | |
local RESPONSE_STATE=$(echo "$RESPONSE" | jq -r '.state') | |
local RESPONSE_ENVIRONMENT=$(echo "$RESPONSE" | jq -r '.environment') | |
# Output the information | |
echo "-> Update $RESPONSE_ENVIRONMENT latest deployment to $RESPONSE_STATE state." | |
else | |
echo "-> No deployment for $ENVIRONMENT environment. No update." | |
fi | |
} | |
# Set inactive state to the latest deployment of branch environments | |
set_inactive_latest_deployment "playsrg-ios-nightly+$BUILD_NAME" | |
set_inactive_latest_deployment "playsrg-tvos-nightly+$BUILD_NAME" | |
set_inactive_latest_deployment "playsrg-ios-beta+$BUILD_NAME" | |
set_inactive_latest_deployment "playsrg-tvos-beta+$BUILD_NAME" |