|
1 | 1 | <a href="https://unly.org"><img src="https://storage.googleapis.com/unly/images/ICON_UNLY.png" align="right" height="20" alt="Unly logo" title="Unly logo" /></a>
|
2 |
| -[](https://codeclimate.com/github/UnlyEd/github-action-store-variable/maintainability) |
3 |
| -[](https://codeclimate.com/github/UnlyEd/github-action-store-variable/test_coverage) |
| 2 | +[](https://codeclimate.com/github/UnlyEd/github-action-deploy-on-vercel/maintainability) |
| 3 | +[](https://codeclimate.com/github/UnlyEd/github-action-deploy-on-vercel/test_coverage) |
4 | 4 |
|
5 |
| - |
6 |
| - |
7 |
| - |
| 5 | + |
| 6 | + |
| 7 | + |
8 | 8 |
|
9 | 9 | # GitHub Action - Store variables between your jobs
|
10 | 10 |
|
|
13 | 13 | ```yaml
|
14 | 14 | name: 'GitHub Action code snippet'
|
15 | 15 | on:
|
| 16 | + pull_request: |
16 | 17 | push:
|
17 | 18 | branches:
|
18 | 19 | - '*'
|
| 20 | + |
19 | 21 | jobs:
|
20 |
| - # On some job, do some stuff an persist variables meant to be re-used in other jobs |
21 |
| - compute-data: |
22 |
| - name: Compute data |
| 22 | + run-example-deployment: |
23 | 23 | runs-on: ubuntu-18.04
|
24 | 24 | steps:
|
25 |
| - # Do your own internal business logic... |
26 |
| - - name: Compute ressource |
27 |
| - run: | |
28 |
| - MAGIC_NUMBER=42 |
29 |
| - echo "Found universal answer: $MAGIC_NUMBER" |
30 |
| - echo "Exporting it as ENV variable..." |
31 |
| - echo "MAGIC_NUMBER=$MAGIC_NUMBER" >> $GITHUB_ENV |
32 |
| -
|
33 |
| - # XXX We recommend to export all your variables at once, at the end of your job |
34 |
| - - name: Export variable for next jobs |
35 |
| - uses: UnlyEd/github-action-store-variable@v2.1.0 # See https://github.com/UnlyEd/github-action-store-variable |
| 25 | + - uses: actions/checkout@v2 |
| 26 | + - uses: UnlyEd/github-action-deploy-on-vercel@latest |
36 | 27 | with:
|
37 |
| - # Persist (store) our MAGIC_NUMBER ENV variable into our store, for the next jobs |
38 |
| - variables: | |
39 |
| - MAGIC_NUMBER=${{ env.MAGIC_NUMBER }} |
| 28 | + command: "vercel examples/static-deployment --confirm --debug --token ${{ secrets.VERCEL_TOKEN }}" |
| 29 | + env: |
| 30 | + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} |
40 | 31 |
|
41 |
| - # In another job, read the previously stored variable and use it |
42 |
| - retrieve-data: |
43 |
| - name: Find & re-use data |
44 |
| - runs-on: ubuntu-18.04 |
45 |
| - needs: compute-data |
46 |
| - steps: |
47 |
| - - name: Import variable MAGIC_NUMBER |
48 |
| - uses: UnlyEd/github-action-store-variable@v2.1.0 # See https://github.com/UnlyEd/github-action-store-variable |
49 |
| - with: |
50 |
| - # List all variables you want to retrieve from the store |
51 |
| - # XXX They'll be automatically added to your ENV |
52 |
| - variables: | |
53 |
| - MAGIC_NUMBER |
54 |
| - - name: Debug output |
55 |
| - run: echo "We have access to $MAGIC_NUMBER" |
| 32 | + - run: "echo \"Found deployment url: ${{ env.VERCEL_DEPLOYMENT_URL }}\"" |
56 | 33 | ```
|
57 | 34 |
|
58 |
| -> If you want to see a real output, check out the output of our code snippet example [here](https://github.com/UnlyEd/github-action-store-variable/actions/runs/537556204). |
59 |
| -
|
60 |
| -See the [Examples section](#examples) for more advanced examples. |
61 |
| -
|
62 | 35 | ## What does this GitHub Action do?
|
63 | 36 |
|
64 |
| -You can use this action to **store variables** in a sort of "global store" for your GitHub Actions. |
| 37 | +You can use this action to deploy a Vercel project online through a GitHub action. |
65 | 38 |
|
66 |
| -Then, you can **read the variables** that have been stored previously. |
| 39 | +The action will return the url of the Vercel deployment _(and store it as environment variable, too)_, it will also apply domain aliases if there are any configured in the Vercel config file (`vercel.config` by default). |
67 | 40 |
|
68 |
| -The variables stored can be read by any job within the same workflow. |
69 |
| -
|
70 |
| -> **N.B**: When you read a variable, **it is automatically added as an ENV variable** and will erase any variable with the same name. |
71 |
| -> |
72 |
| -> This behavior helps keeping the code cleaner by only manipulating (reading/writing) ENV variables. |
73 |
| -> In v1, we had to read the variables from a JSON object, and [it was ugly](https://github.com/UnlyEd/github-action-store-variable/blob/c4143c0d7f/.github/workflows/run-integration-test.yml#L29). |
74 |
| -
|
75 |
| -> N.B: You can both **read and write** in the same action. |
| 41 | +> It works quite differently compared to [`vercel-action`](https://github.com/marketplace/actions/vercel-action). |
76 | 42 |
|
77 | 43 | ## Why/when should you use it?
|
78 | 44 |
|
79 |
| -GitHub Actions doesn't allow to natively re-use variables between jobs. |
80 |
| -
|
81 |
| -If you need to **re-use variables defined in a job in other** (subsequent) jobs, then you can use this action. |
| 45 | +You want to run a custom command that (amongst other things) performs a Vercel deployment. |
82 | 46 |
|
83 | 47 | ### Action's API
|
84 | 48 |
|
85 | 49 | #### Inputs
|
86 | 50 |
|
87 | 51 | Name | Required | Default | Description
|
88 | 52 | --- | --- |--- |---
|
89 |
| -`variables`|✅| | Write variable: `VAR=VALUE` - Read variable: `VAR` |
90 |
| -`delimiter`|✖️|`\r?\n`| Regex delimiter between each variable, defaults to normal line break |
91 |
| -`failIfNotFound`|✖️|`false`| If true, will throw an error (and crash CI) when attempting to read a variable that doesn't exist in the store |
| 53 | +`command`|✅| | Command starting the vercel deployment |
| 54 | +`applyDomainAliases`|✖️|`true`| If true, will create Vercel aliases using the aliases specified in the vercel config file |
| 55 | +`failIfAliasNotLinked`|✖️|`false`| If true, will throw an error (and crash CI) when there is an error about aliases link |
92 | 56 |
|
93 | 57 | #### Outputs
|
94 | 58 |
|
95 |
| -There are no outputs for this action, reading variables **automatically** adds these variables in `${{ env }}`. |
96 |
| - |
97 |
| -For example, if you read a variable named `VAR`, you can then access it by using `${{ env.VAR }}`. |
98 |
| - |
99 |
| -## Examples |
| 59 | +The below variables are available as outputs, but are also **injected as environment variables automatically**. |
100 | 60 |
|
101 |
| -### 1. Save one variable |
102 |
| - |
103 |
| -```yaml |
104 |
| -- name: Export one variable |
105 |
| - uses: UnlyEd/github-action-store-variable@v2.1.0 |
106 |
| - with: |
107 |
| - variables: FOO=BAR |
108 |
| -``` |
109 |
| - |
110 |
| -### 2. Save many variables |
111 |
| - |
112 |
| -```yaml |
113 |
| -- name: Export many variables |
114 |
| - uses: UnlyEd/github-action-store-variable@v2.1.0 |
115 |
| - with: |
116 |
| - variables: | |
117 |
| - FOO=BAR |
118 |
| - STAGE=production |
119 |
| -``` |
120 |
| - |
121 |
| -> Pro-tip: We recommend always using the `variables: |` syntax (multi lines), because it's just simpler to add more variables later on. |
122 |
| - |
123 |
| -### 3. Save one variable and read another |
124 |
| - |
125 |
| -```yaml |
126 |
| -- name: Export one variable |
127 |
| - uses: UnlyEd/github-action-store-variable@v2.1.0 |
128 |
| - with: |
129 |
| - # Writes "FOO" and reads "STAGE" |
130 |
| - variables: | |
131 |
| - FOO=BAR |
132 |
| - STAGE |
133 |
| -``` |
134 |
| - |
135 |
| -### 4. Save many variables using a custom delimiter |
136 |
| - |
137 |
| -```yaml |
138 |
| -- name: Export many variables |
139 |
| - uses: UnlyEd/github-action-store-variable@v2.1.0 |
140 |
| - with: |
141 |
| - delimiter: ':' |
142 |
| - variables: FOO=BAR:STAGE=production |
143 |
| -``` |
144 |
| - |
145 |
| -### 5. Retrieve one variable |
146 |
| - |
147 |
| -```yaml |
148 |
| -- name: Import variable MAGIC_NUMBER |
149 |
| - uses: UnlyEd/github-action-store-variable@v2.1.0 |
150 |
| - with: |
151 |
| - variables: FOO |
152 |
| -``` |
153 |
| - |
154 |
| -### 6. Retrieve many variables |
155 |
| - |
156 |
| -```yaml |
157 |
| -- name: Import variable MAGIC_NUMBER |
158 |
| - uses: UnlyEd/github-action-store-variable@v2.1.0 |
159 |
| - with: |
160 |
| - variables: | |
161 |
| - FOO |
162 |
| - STAGE |
163 |
| -``` |
164 |
| - |
165 |
| -### 7. Retrieve many variables using a custom delimiter |
166 |
| - |
167 |
| -```yaml |
168 |
| -- name: Import variable MAGIC_NUMBER |
169 |
| - uses: UnlyEd/github-action-store-variable@v2.1.0 |
170 |
| - with: |
171 |
| - delimiter: ';' |
172 |
| - variables: FOO;STAGE |
173 |
| -``` |
174 |
| - |
175 |
| -### 8. Crash CI if variable doesn't exist |
176 |
| - |
177 |
| -```yaml |
178 |
| -- name: Import variable MAGIC_NUMBER |
179 |
| - uses: UnlyEd/github-action-store-variable@v2.1.0 |
180 |
| - with: |
181 |
| - failIfNotFound: true |
182 |
| - variables: WRONG_VARIABLE |
183 |
| -``` |
| 61 | +- `VERCEL_DEPLOYMENT_URL`: Full Vercel deployment url (parsed from the deployment logs), e.g: `https://xxx.vercel.app` |
| 62 | +- `VERCEL_DEPLOYMENT_DOMAIN`: Url without the protocol declaration, e.g: `xxx.vercel.app` |
| 63 | +- `VERCEL_ALIASES_ERROR`: _(optional)_ Vercel errors during domain aliasing |
184 | 64 |
|
185 |
| -> N.B: If you want to crash only for some variables, then you can call 2 times the `UnlyEd/github-action-store-variable` and have `failIfNotFound: true` in one of them. |
| 65 | +> Hint: You can use `${{ env.VERCEL_DEPLOYMENT_URL }}` in you GitHub Action to read the deployment URL, after the action has run. |
186 | 66 |
|
187 | 67 | ## :hugs: Community examples :heart:
|
188 | 68 |
|
189 | 69 | Here are a few community-powered examples, those are usually advanced use-cases!
|
190 | 70 |
|
191 |
| -- [Next Right Now](https://github.com/UnlyEd/next-right-now/blob/60455642a5c5248c3e0e9604de080e24ef9eed0a/.github/workflows/deploy-vercel-staging.yml#L250-L260) _(Disclosure: We're the author!)_ |
| 71 | +- [Next Right Now](https://github.com/UnlyEd/next-right-now) _(Disclosure: We're the author!)_ |
192 | 72 |
|
193 | 73 | ---
|
194 | 74 |
|
|
0 commit comments