|
1 |
| -name: 'Netlify Deploy' |
2 |
| -author: 'Jo Colina' |
3 |
| -description: 'Netlify Deploy' |
4 |
| - |
| 1 | +--- |
| 2 | +name: Netlify Deploy |
| 3 | +author: Jo Colina |
| 4 | +description: Netlify Deploy |
5 | 5 | inputs:
|
6 | 6 | NETLIFY_AUTH_TOKEN:
|
7 |
| - description: 'Auth token to use with netlify' |
| 7 | + description: Auth token to use with netlify |
8 | 8 | required: true
|
9 |
| - default: '' |
10 |
| - |
| 9 | + default: "" |
11 | 10 | NETLIFY_SITE_ID:
|
12 |
| - description: 'Your Netlify site id' |
| 11 | + description: Your Netlify site id |
13 | 12 | required: true
|
14 |
| - default: '' |
15 |
| - |
| 13 | + default: "" |
16 | 14 | NETLIFY_DEPLOY_TO_PROD:
|
17 |
| - description: 'Should the site be deployed to production?' |
| 15 | + description: Should the site be deployed to production? |
18 | 16 | required: false
|
19 | 17 | default: false
|
20 |
| - |
21 | 18 | NETLIFY_DEPLOY_MESSAGE:
|
22 |
| - description: 'A deploy message' |
| 19 | + description: A deploy message |
23 | 20 | required: false
|
24 |
| - default: '' |
25 |
| - |
| 21 | + default: "" |
26 | 22 | build_directory:
|
27 |
| - description: 'Directory where built files are stored' |
| 23 | + description: Directory where built files are stored |
28 | 24 | required: true
|
29 |
| - default: 'build' |
30 |
| - |
| 25 | + default: build |
31 | 26 | functions_directory:
|
32 |
| - description: 'Directory where built files are stored' |
| 27 | + description: Directory where built files are stored |
33 | 28 | required: false
|
34 |
| - default: '' |
35 |
| - |
| 29 | + default: "" |
36 | 30 | install_command:
|
37 |
| - description: 'Command to install dependencies' |
| 31 | + description: Command to install dependencies |
38 | 32 | required: false
|
39 |
| - default: '' |
40 |
| - |
| 33 | + default: "" |
41 | 34 | build_command:
|
42 |
| - description: 'Command to build static website' |
| 35 | + description: Command to build static website |
43 | 36 | required: false
|
44 |
| - default: 'npm run build' |
45 |
| - |
| 37 | + default: npm run build |
46 | 38 | deploy_alias:
|
47 |
| - description: 'Deployment Subdomain name' |
| 39 | + description: Deployment Subdomain name |
48 | 40 | required: false
|
49 |
| - default: '' |
50 |
| - |
| 41 | + default: "" |
51 | 42 | node_version:
|
52 |
| - description: 'Node version or arguments compatible with `nvm install`' |
| 43 | + description: Node version or arguments compatible with `nvm install` |
53 | 44 | required: false
|
54 |
| - default: '' |
55 |
| - |
| 45 | + default: "" |
56 | 46 | use_nvm:
|
57 |
| - description: 'Enables you to disable nvm altogether' |
| 47 | + description: Enables you to disable nvm altogether |
58 | 48 | required: false
|
59 | 49 | default: true
|
60 |
| - |
61 | 50 | outputs:
|
62 | 51 | NETLIFY_OUTPUT:
|
63 |
| - description: "netlify command output" |
| 52 | + description: netlify command output |
64 | 53 | NETLIFY_PREVIEW_URL:
|
65 |
| - description: "deployment preview URL" |
| 54 | + description: deployment preview URL |
66 | 55 | NETLIFY_LOGS_URL:
|
67 |
| - description: "deployment preview logs url" |
| 56 | + description: deployment preview logs url |
68 | 57 | NETLIFY_LIVE_URL:
|
69 |
| - description: "deployment URL" |
70 |
| - |
| 58 | + description: deployment URL |
71 | 59 | runs:
|
72 |
| - using: 'docker' |
73 |
| - image: 'Dockerfile' |
74 |
| - args: |
75 |
| - - ${{ inputs.NETLIFY_AUTH_TOKEN }} |
76 |
| - - ${{ inputs.NETLIFY_SITE_ID }} |
77 |
| - - ${{ inputs.NETLIFY_DEPLOY_TO_PROD }} |
78 |
| - - ${{ inputs.build_directory }} |
79 |
| - - ${{ inputs.functions_directory }} |
80 |
| - - ${{ inputs.install_command }} |
81 |
| - - ${{ inputs.build_command }} |
82 |
| - - ${{ inputs.deploy_alias }} |
83 |
| - - ${{ inputs.node_version }} |
| 60 | + using: composite |
| 61 | + steps: |
| 62 | + - name: "Install node through NVM if needed" |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + if [[ "${{ inputs.use_nvm }}" == "true" ]] && ([[ -n "${{ inputs.node_version }}" ]] || [[ -e ".nvmrc" ]]) |
| 66 | + then |
| 67 | + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash |
| 68 | + [ -s "$HOME/.nvm/nvm.sh" ] && \. "$HOME/.nvm/nvm.sh" |
| 69 | + if [[ -n "${{ inputs.node_version }}" ]] |
| 70 | + then |
| 71 | + nvm install "${{ inputs.node_version }}" |
| 72 | + else |
| 73 | + nvm install |
| 74 | + fi |
| 75 | + else |
| 76 | + echo "Node installation has been omitted" |
| 77 | + fi |
| 78 | + - name: "Run install command" |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + if [[ -n "${{ inputs.install_command }}" ]] |
| 82 | + then |
| 83 | + ${{ inputs.install_command }} |
| 84 | + elif [[ -f yarn.lock ]] |
| 85 | + then |
| 86 | + yarn |
| 87 | + else |
| 88 | + npm i |
| 89 | + fi |
| 90 | + - name: "Run build command" |
| 91 | + shell: bash |
| 92 | + run: | |
| 93 | + if [[ -n "${{ inputs.build_command }}" ]] |
| 94 | + then |
| 95 | + ${{ inputs.build_command }} |
| 96 | + else |
| 97 | + npm run build |
| 98 | + fi |
| 99 | + - name: "Deploy to Netlify" |
| 100 | + shell: bash |
| 101 | + run: | |
| 102 | + export NETLIFY_SITE_ID="${{ inputs.NETLIFY_SITE_ID }}" |
| 103 | + export NETLIFY_AUTH_TOKEN="${{ inputs.NETLIFY_AUTH_TOKEN }}" |
| 104 | +
|
| 105 | + COMMAND="netlify deploy --dir=${{ inputs.build_directory }} --functions=${{ inputs.functions_directory }} --message=\"${{ inputs.NETLIFY_DEPLOY_MESSAGE }}\"" |
| 106 | +
|
| 107 | + if [[ "${{ inputs.NETLIFY_DEPLOY_TO_PROD }}" == "true" ]] |
| 108 | + then |
| 109 | + COMMAND+=" --prod" |
| 110 | + elif [[ -n "${{ inputs.deploy_alias }}" ]] |
| 111 | + then |
| 112 | + COMMAND+=" --alias ${{ inputs.deploy_alias }}" |
| 113 | + fi |
| 114 | +
|
| 115 | + # Deploy with netlify |
| 116 | + OUTPUT=$(sh -c "$COMMAND") |
| 117 | +
|
| 118 | + NETLIFY_OUTPUT=$(echo "$OUTPUT") |
| 119 | + NETLIFY_PREVIEW_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*(--)[a-zA-Z0-9./?=_-]*') #Unique key: -- |
| 120 | + NETLIFY_LOGS_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://app.netlify.com/[a-zA-Z0-9./?=_-]*') #Unique key: app.netlify.com |
| 121 | + NETLIFY_LIVE_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*' | grep -Eov "netlify.com") #Unique key: don't containr -- and app.netlify.com |
| 122 | +
|
| 123 | + echo "NETLIFY_OUTPUT<<EOF" >> $GITHUB_ENV |
| 124 | + echo "$NETLIFY_OUTPUT" >> $GITHUB_ENV |
| 125 | + echo "EOF" >> $GITHUB_ENV |
| 126 | +
|
| 127 | + echo "NETLIFY_PREVIEW_URL<<EOF" >> $GITHUB_ENV |
| 128 | + echo "$NETLIFY_PREVIEW_URL" >> $GITHUB_ENV |
| 129 | + echo "EOF" >> $GITHUB_ENV |
| 130 | +
|
| 131 | + echo "NETLIFY_LOGS_URL<<EOF" >> $GITHUB_ENV |
| 132 | + echo "$NETLIFY_LOGS_URL" >> $GITHUB_ENV |
| 133 | + echo "EOF" >> $GITHUB_ENV |
84 | 134 |
|
| 135 | + echo "NETLIFY_LIVE_URL<<EOF" >> $GITHUB_ENV |
| 136 | + echo "$NETLIFY_LIVE_URL" >> $GITHUB_ENV |
| 137 | + echo "EOF" >> $GITHUB_ENV |
85 | 138 | branding:
|
86 | 139 | icon: activity
|
87 | 140 | color: blue
|
0 commit comments