|
| 1 | +name: Create Preview Environment |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [opened, synchronize, reopened] |
| 5 | + |
| 6 | +env: |
| 7 | + SERVICE_NAME: greeter-${{ github.event.number }} |
| 8 | + |
| 9 | +jobs: |
| 10 | + new-func: |
| 11 | + name: Create Preview Environment |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v3 |
| 15 | + |
| 16 | + - id: auth |
| 17 | + name: 'Authenticate to Google Cloud' |
| 18 | + uses: 'google-github-actions/auth@v0' |
| 19 | + with: |
| 20 | + credentials_json: '${{ secrets.GCP_CREDS }}' |
| 21 | + |
| 22 | + - name: 'Set up Cloud SDK' |
| 23 | + uses: 'google-github-actions/setup-gcloud@v0' |
| 24 | + with: |
| 25 | + project_id: space-cloud |
| 26 | + |
| 27 | + - name: 'Deploy Function' |
| 28 | + run: | |
| 29 | + gcloud functions deploy $SERVICE_NAME \ |
| 30 | + --set-env-vars='PR_NO=${{ github.event.number }}' \ |
| 31 | + --allow-unauthenticated --trigger-http --gen2 --runtime go116 --region us-east1 --entry-point=GreeterGet |
| 32 | +
|
| 33 | + - name: 'Get PREVIEW URL' |
| 34 | + run: | |
| 35 | + echo PREVIEW_URL=$(gcloud functions describe $SERVICE_NAME --gen2 --region us-east1 --format="value(serviceConfig.uri)") >> $GITHUB_ENV |
| 36 | + |
| 37 | + - uses: actions/github-script@v5 |
| 38 | + with: |
| 39 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 40 | + script: | |
| 41 | + github.rest.issues.createComment({ |
| 42 | + issue_number: context.issue.number, |
| 43 | + owner: context.repo.owner, |
| 44 | + repo: context.repo.repo, |
| 45 | + body: `Preview URL: ${process.env.PREVIEW_URL}` |
| 46 | + }) |
0 commit comments