-
Notifications
You must be signed in to change notification settings - Fork 10
/
action.yml
83 lines (73 loc) · 3.29 KB
/
action.yml
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
73
74
75
76
77
78
79
80
81
82
83
name: 'Branch Preview'
description: 'Preview Fastly Service'
inputs:
project_directory:
description: 'Directory of the project to build, relative to the repository root.'
required: false
default: './'
fastly-api-token:
description: 'The Fastly API token to use for interacting with Fastly API'
required: true
github-token:
description: 'The GitHub token to use for downloading the Fastly CLI'
required: true
outputs:
domain:
description: "Preview domain for Fastly Compute Service"
value: ${{ steps.domain.outputs.DOMAIN }}
service_name:
description: "Preview service name for Fastly Compute Service"
value: ${{ steps.service-name.outputs.SERVICE_NAME }}
runs:
using: "composite"
steps:
# Download Fastly CLI
- name: Set up Fastly CLI
uses: fastly/compute-actions/setup@v5
with:
token: ${{ inputs.github-token }}
cli_version: 'latest'
- run: yarn
working-directory: ${{ inputs.project_directory }}
shell: bash
# Create a new Fastly Service name with the PR number appended
- name: Set service-name
id: service-name
working-directory: ${{ inputs.project_directory }}
run: echo "SERVICE_NAME=$(yq '.name' fastly.toml)-${{ github.event.number }}" >> "$GITHUB_OUTPUT"
shell: bash
# Delete the Fastly Service
- if: github.event.action == 'closed'
working-directory: ${{ inputs.project_directory }}
run: fastly service delete --quiet --service-name ${{ steps.service-name.outputs.SERVICE_NAME }} --force --token ${{ inputs.fastly-api-token }} || true
shell: bash
env:
fastly_api_token: ${{ inputs.fastly-api-token }}
# Deploy to Fastly and let Fastly choose a subdomain of edgecompute.app to attach to the service
- if: github.event.action != 'closed'
working-directory: ${{ inputs.project_directory }}
run: |
fastly compute publish --verbose -i --token ${{ inputs.fastly-api-token }} --service-name ${{ steps.service-name.outputs.SERVICE_NAME }}
shell: bash
env:
fastly_api_token: ${{ inputs.fastly-api-token }}
# Retrieve the newly created domain for the service and add it to the pull-request summary
- if: github.event.action != 'closed'
working-directory: ${{ inputs.project_directory }}
run: fastly domain list --quiet --version latest --json --service-name="${{ steps.service-name.outputs.SERVICE_NAME }}" --token ${{ inputs.fastly-api-token }} | jq -r '.[0].Name'
shell: bash
env:
FASTLY_API_TOKEN: ${{ inputs.fastly-api-token }}
- if: github.event.action != 'closed'
working-directory: ${{ inputs.project_directory }}
name: Set domain
shell: bash
id: domain
run: echo "DOMAIN=$(fastly domain list --quiet --version latest --json --service-name="${{ steps.service-name.outputs.SERVICE_NAME }}" --token ${{ inputs.fastly-api-token }} | jq -r '.[0].Name')" >> "$GITHUB_OUTPUT"
env:
FASTLY_API_TOKEN: ${{ inputs.fastly-api-token }}
- if: github.event.action != 'closed'
working-directory: ${{ inputs.project_directory }}
shell: bash
name: Add domain to summary
run: echo 'This pull-request has been deployed to Fastly and is available at <https://${{ steps.domain.outputs.DOMAIN }}> 🚀' >> $GITHUB_STEP_SUMMARY