node22 supported #2715
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: Manage environment | |
on: | |
pull_request_target: | |
branches: [main] | |
types: | |
- opened | |
- reopened | |
- closed | |
env: | |
PLATFORMSH_CLI_NO_INTERACTION: 1 | |
PLATFORM_PROJECT: ${{ vars.PROJECT_ID }} | |
PLATFORMSH_CLI_DEFAULT_TIMEOUT: 60 # Increase timeout for CLI commands | |
PLATFORMSH_CLI_TOKEN: ${{ secrets.PLATFORMSH_CLI_TOKEN }} | |
BRANCH_TITLE: ${{ vars.BFF_PREFIX }}-${{ github.event.number }} | |
jobs: | |
activate_environment: | |
runs-on: ubuntu-latest | |
# Activate when a PR is opened, but not for forks (handled through `build-from-fork` workflow) | |
if: >- | |
(github.event.action == 'opened' || | |
github.event.action== 'reopened') && | |
github.event.pull_request.head.repo.id == 21975579 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Set up workflow environment to use the Platform.sh CLI | |
- name: Set up Platform.sh CLI | |
uses: ./.github/actions/set-up-cli | |
- name: Set environment title | |
env: | |
# Github does not escape PR titles before swapping the token with the value. This means that in a shell context | |
# if a PR title includes a single or double quote, it will break the shell command. If you try to enclose | |
# the value with quotes before assigning it to a variable, it will also break. The only way around it is to | |
# assign it as an environmental variable for the step which will force GitHub to escape it properly for the | |
# shell, and *then* you can use it | |
PR_TITLE: ${{ github.event.pull_request.title }} | |
run: | | |
# @todo - this is the same as the last step in build-from-fork:jobs:build. See if we can combine the two | |
newTitle="(pr-${{ github.event.number }}) ${PR_TITLE}" | |
currentTitle=$(platform environment:info -e ${{ github.event.pull_request.head.ref }} title) | |
if [[ "${currentTitle}" != "${newTitle}" ]]; then | |
echo "::notice::Setting environment's title" | |
platform environment:info -e ${{ github.event.pull_request.head.ref }} title "${newTitle}" | |
fi | |
- name: Activate environment | |
run: platform environment:activate --no-wait ${{ github.event.pull_request.head.ref }} | |
deactivate_environment: | |
runs-on: ubuntu-latest | |
# For non-forked PRs | |
# Deactivate when a PR is closed | |
# Don't need to run on merges since the integration takes care of it | |
if: >- | |
github.event.action == 'closed' && | |
github.event.pull_request.merged == false && | |
github.event.pull_request.head.repo.id == 21975579 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Set up workflow environment to use the Platform.sh CLI | |
- name: Set up Platform.sh CLI | |
uses: ./.github/actions/set-up-cli | |
- name: Close environment | |
run: platform environment:deactivate --no-delete-branch ${{ github.event.pull_request.head.ref }} | |
deactivate_forked_environment: | |
runs-on: ubuntu-latest | |
# For forked PRs labelled as build-fork | |
# Delete branch when a PR is closed | |
if: >- | |
github.event.action == 'closed' && | |
github.event.pull_request.head.repo.id != 21975579 && | |
contains(github.event.pull_request.labels.*.name, 'build-fork') | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Check if Git branch exists | |
id: branch_exists | |
# Check if the Git branch exists | |
run: | | |
BRANCH=$(git ls-remote --heads origin ${{ env.BRANCH_TITLE }}) | |
echo $BRANCH | |
if [[ -n $BRANCH ]]; then | |
echo "branch_exists=true" >> $GITHUB_OUTPUT | |
else | |
echo "branch_exists=false" >> $GITHUB_OUTPUT | |
fi | |
# If the branch or environment exists, delete it from Platform.sh | |
- name: Delete branch | |
if: steps.branch_exists.outputs.branch_exists == 'true' | |
run: | | |
git push origin -d ${{ env.BRANCH_TITLE }} | |
# Set up workflow environment to use the Platform.sh CLI | |
- name: Set up Platform.sh CLI | |
# If the Git branch was deleted, skip checks for the environment | |
if: steps.branch_exists.outputs.branch_exists != 'true' | |
uses: ./.github/actions/set-up-cli | |
- name: Check if environment exists | |
id: environment_exists | |
if: steps.branch_exists.outputs.branch_exists != 'true' | |
# Check if the built environment exists | |
run: | | |
BRANCH=$(platform environments --pipe --columns title | grep ${{ env.BRANCH_TITLE }}) | |
if [[ -n $BRANCH ]]; then | |
echo "environment_exists=true" >> $GITHUB_OUTPUT | |
fi | |
# If the branch or environment exists, delete it from Platform.sh | |
- name: Delete environment | |
if: steps.branch_exists.outputs.branch_exists != 'true' && steps.environment_exists.outputs.environment_exists == 'true' | |
run: | | |
platform environment:delete --delete-branch --no-wait ${{ env.BRANCH_TITLE }} |