forked from platformsh/platformsh-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (62 loc) · 3.06 KB
/
build-from-fork.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Build from fork
on:
pull_request_target:
branches: [main]
types: [labeled,unlabeled,synchronize]
env:
PLATFORMSH_CLI_NO_INTERACTION: 1
PLATFORM_PROJECT: 652soceglkw4u
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