|
| 1 | +name: Create Tutorial Workspace |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: ["main"] |
| 6 | + types: |
| 7 | + - closed |
| 8 | + |
| 9 | +jobs: |
| 10 | + create-workspace: |
| 11 | + if: github.event.pull_request.merged == true |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Get changed files |
| 19 | + id: get-changed-files |
| 20 | + uses: tj-actions/changed-files@v45 |
| 21 | + |
| 22 | + - name: Get changed folder |
| 23 | + id: get-changed-folder |
| 24 | + env: |
| 25 | + ALL_CHANGED_FILES: ${{ steps.get-changed-files.outputs.all_changed_files }} |
| 26 | + run: | |
| 27 | + first_file=$(echo "$ALL_CHANGED_FILES" | tr ' ' '\n' | grep "tutorials" | head -n 1) |
| 28 | + top_level_dir=$(echo "$first_file" | cut -d'/' -f1,2) |
| 29 | + echo "dir=$top_level_dir" >> "$GITHUB_OUTPUT" |
| 30 | +
|
| 31 | + - name: Check for config file |
| 32 | + working-directory: ${{ steps.get-changed-folder.outputs.dir }} |
| 33 | + run: | |
| 34 | + pwd |
| 35 | + if [ ! -f tutorial-config.json ]; then |
| 36 | + echo "tutorial-config.json not found. Exiting." |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | +
|
| 40 | + - name: Setup node |
| 41 | + uses: actions/setup-node@v3 |
| 42 | + with: |
| 43 | + node-version: 22.4 |
| 44 | + |
| 45 | + - name: Install dependencies |
| 46 | + working-directory: ${{ steps.get-changed-folder.outputs.dir }} |
| 47 | + run: | |
| 48 | + node -v |
| 49 | + npm -v |
| 50 | + npm install |
| 51 | +
|
| 52 | + - name: Run build |
| 53 | + working-directory: ${{ steps.get-changed-folder.outputs.dir }} |
| 54 | + run: | |
| 55 | + pwd |
| 56 | + npm run build |
| 57 | +
|
| 58 | + - name: Prep deploy |
| 59 | + working-directory: ${{ steps.get-changed-folder.outputs.dir }} |
| 60 | + run: | |
| 61 | + mkdir -p server |
| 62 | + cd server |
| 63 | + mkdir -p ./public |
| 64 | + cp -r ../dist/* ./public |
| 65 | + rm -rf ../dist |
| 66 | + cp -r $GITHUB_WORKSPACE/scripting/DummyServer/* . |
| 67 | +
|
| 68 | + NAME=$(jq -r '.slug' ../tutorial-config.json) |
| 69 | + VERSION=$(jq -r '.version' ../tutorial-config.json) |
| 70 | + VERSION=${VERSION//./-} |
| 71 | + sed -i "s/<NAME>/$NAME/g" vcr.yml |
| 72 | + sed -i "s/<ENV>/$VERSION/g" vcr.yml |
| 73 | +
|
| 74 | + cat vcr.yml |
| 75 | +
|
| 76 | + - name: Install Cloud Runtime CLI |
| 77 | + uses: Vonage/cloud-runtime-cli@main |
| 78 | + |
| 79 | + - name: Deploy |
| 80 | + id: deploy |
| 81 | + working-directory: ${{ steps.get-changed-folder.outputs.dir }}/server |
| 82 | + run: | |
| 83 | + vcr deploy --api-key ${{ vars.VONAGE_API_KEY }} --api-secret ${{ secrets.VONAGE_API_SECRET }} --region aws.${{ vars.VCR_REGION }} --graphql-endpoint https://graphql.${{ vars.VCR_REGION }}.runtime.vonage.cloud/v1/graphql 2>&1 | tee deploy-vcr-logs.log |
| 84 | + url=$(grep -oP 'https://neru-\S+' deploy-vcr-logs.log) |
| 85 | + sanitized_url=$(echo "$url" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g") |
| 86 | + echo "url=$sanitized_url" >> "$GITHUB_OUTPUT" |
| 87 | +
|
| 88 | + - name: Create Workspace Folder |
| 89 | + working-directory: ${{ steps.get-changed-folder.outputs.dir }} |
| 90 | + run: | |
| 91 | + rm -rf server ws |
| 92 | + mkdir -p ws |
| 93 | + cd ws |
| 94 | + pwd |
| 95 | + cp ../tutorial-config.json . |
| 96 | + cp -r $GITHUB_WORKSPACE/scripting/DummyWorkspace/. . |
| 97 | + cp $GITHUB_WORKSPACE/scripting/createWorkspace.sh . |
| 98 | + ls -a |
| 99 | + ./createWorkspace.sh ${{ steps.deploy.outputs.url }} |
| 100 | +
|
| 101 | + - name: Tag the commit |
| 102 | + id: tag-commit |
| 103 | + working-directory: ${{ steps.get-changed-folder.outputs.dir }} |
| 104 | + run: | |
| 105 | + git config user.name "GitHub Actions" |
| 106 | + git config user.email "actions@github.com" |
| 107 | + git add --all |
| 108 | +
|
| 109 | + slug=$(jq -r '.slug' tutorial-config.json) |
| 110 | + version=$(jq -r '.version' tutorial-config.json) |
| 111 | + TAG_NAME="${slug}-v${version}" |
| 112 | +
|
| 113 | + git commit -m "Adding workspace for ${TAG_NAME}" |
| 114 | + git tag -a $TAG_NAME -m "Tagging commit for version ${TAG_NAME}" |
| 115 | +
|
| 116 | + git push |
| 117 | + git push origin $TAG_NAME |
| 118 | +
|
| 119 | + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT |
| 120 | +
|
| 121 | + - name: Zip Workspace |
| 122 | + uses: TheDoctor0/zip-release@0.7.6 |
| 123 | + with: |
| 124 | + type: "zip" |
| 125 | + directory: "${{ steps.get-changed-folder.outputs.dir }}/ws" |
| 126 | + path: "." |
| 127 | + filename: "ws.zip" |
| 128 | + exclusions: "tutorial-config.json createWorkspace.sh" |
| 129 | + |
| 130 | + - name: Upload a Build Artifact |
| 131 | + id: upload-release-artifact |
| 132 | + uses: actions/upload-artifact@v4.0.0 |
| 133 | + with: |
| 134 | + path: "${{ steps.get-changed-folder.outputs.dir }}/ws/ws.zip" |
| 135 | + |
| 136 | + - name: Create release assets |
| 137 | + uses: ncipollo/release-action@v1 |
| 138 | + with: |
| 139 | + name: Release ${{ steps.tag-commit.outputs.tag_name }} |
| 140 | + artifacts: "${{ steps.get-changed-folder.outputs.dir }}/ws/ws.zip" |
| 141 | + body: Download and Upload the ws.zip file to Code Hub now. |
| 142 | + tag: ${{ steps.tag-commit.outputs.tag_name }} |
0 commit comments