Update add-on-subscription.md #4342
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: Build from fork | |
on: | |
pull_request_target: | |
branches: [main] | |
types: [labeled,unlabeled,synchronize] | |
env: | |
PLATFORMSH_CLI_NO_INTERACTION: 1 | |
PLATFORM_PROJECT: ${{ vars.PROJECT_ID }} | |
PLATFORMSH_CLI_DEFAULT_TIMEOUT: 60 # Increase timeout for CLI commands | |
SLEEP_TIME: 5 | |
NUM_TRIES: 30 | |
BRANCH_TITLE: ${{ vars.BFF_PREFIX }}-${{ github.event.number }} | |
jobs: | |
build: | |
if: github.event.label.name == 'build-fork' || contains(github.event.pull_request.labels.*.name, 'build-fork') | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
token: ${{ secrets.WORKFLOW_TOKEN }} | |
# Set up workflow environment to use the Platform.sh CLI | |
- name: Set up Platform.sh CLI | |
uses: ./.github/actions/set-up-cli | |
# Create an environment and activate it | |
- env: | |
PLATFORMSH_CLI_TOKEN: ${{ secrets.PLATFORMSH_CLI_TOKEN }} | |
# @see activate_environment:Set environment title:env in manage-environment.yaml | |
PR_TITLE: ${{ github.event.pull_request.title }} | |
run: | | |
# Get most recent changes | |
git checkout ${{ github.event.pull_request.head.sha }} | |
# Put most recent changes on the branch | |
echo "Switching to branch ${{ env.BRANCH_TITLE }}" | |
git switch -C ${{ env.BRANCH_TITLE }} | |
echo "Pushing most recent changes" | |
git push --force origin ${{ env.BRANCH_TITLE }} | |
# has platform.sh received our new branch? | |
counter=0 | |
branchReceived="" | |
echo "::notice::Checking if Platform.sh has received our new branch..." | |
while (( counter < ${{ env.NUM_TRIES }} )) && [[ -z "${branchReceived}" ]]; do | |
sleep ${{ env.SLEEP_TIME }} | |
echo "::notice::Attempt ${counter} of ${{ env.NUM_TRIES }}" | |
branchReceived=$(platform project:curl /environments | jq --arg branch "${{ env.BRANCH_TITLE }}" -r '.[] | select(.name | contains($branch))'); | |
counter=$((++counter)) | |
done | |
if [[ -z "${branchReceived}" ]]; then | |
echo "::warning::It appears that Platform.sh did not receive our branch ${{ env.BRANCH_TITLE }}. Please look at the logs and try again." | |
exit 24; | |
else | |
echo "::notice::Branch ${{ env.BRANCH_TITLE }} was successfully pushed to Platform.sh. Continuing..." | |
fi | |
# If environment not active, activate it | |
if ! $(platform environments --format plain --columns title,status | grep '${{ env.BRANCH_TITLE }}' | grep -q Active); then | |
echo "::notice::Updating Platform.sh environment title for better tracking..." | |
# in this case we DO want to statically include `pr-##` since we're referring to a pull request number | |
newTitle="(pr-${{ github.event.number }}) ${PR_TITLE}" | |
platform environment:info title "${newTitle}" -e ${{ env.BRANCH_TITLE }} | |
echo "::notice::Activating environment ${{ env.BRANCH_TITLE }}" | |
platform environment:activate -e ${{ env.BRANCH_TITLE }} | |
fi |