Skip to content

Commit e02607f

Browse files
authored
(Major) Implement doc & refactoring workflow demonstration (#4)
1 parent fe04d8e commit e02607f

17 files changed

+128
-198
lines changed

.github/workflows/check-build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ on:
99
pull_request:
1010
push:
1111
branches:
12-
- main
13-
- 'releases/*'
12+
- '*'
1413

1514
jobs:
1615
run-build-test:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 'GitHub Action deploy example'
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- '*'
7+
8+
jobs:
9+
run-example-deployment:
10+
runs-on: ubuntu-18.04
11+
steps:
12+
- uses: actions/checkout@v2
13+
# with:
14+
# path: "github-action-deploy-on-vercel" # Act doesn't work if not specifying the path. See https://github.com/nektos/act/issues/228
15+
- uses: ./
16+
with:
17+
command: "yarn deploy:example --token ${{ secrets.VERCEL_TOKEN }}"
18+
applyDomainAliases: true
19+
failIfAliasNotLinked: false
20+
env:
21+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
22+
23+
- run: "echo \"Found deployment url: ${{ env.VERCEL_DEPLOYMENT_URL }}\""
Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
# Summary:
2-
# Test the GitHub Action using an integration test.
3-
# Makes sure the GitHub Action works properly when running on a clean machine, without building anything (integration test).
4-
# This integration test will break if the Vercel project or deployment are deleted, or if the VERCEl_TOKEN doesn't have access to the deployment url.
5-
#
6-
# See https://github.com/actions/checkout https://github.com/actions/checkout/releases/tag/v2
7-
81
name: 'GitHub Action integration test'
92
on:
103
pull_request:
114
push:
125
branches:
13-
- main
14-
- 'releases/*'
6+
- '*'
157

168
jobs:
179
run-integration-test:
@@ -20,14 +12,11 @@ jobs:
2012
- uses: actions/checkout@v2
2113
- uses: ./
2214
with:
23-
command: "echo 'yarn vercel:cleanup && yarn vercel:deploy --local-config=vercel.customer1.staging.json and found https://app.vercel.app'"
15+
command: "yarn test:integration"
16+
applyDomainAliases: true
17+
failIfAliasNotLinked: false
2418
env:
25-
VERCEL_TOKEN: "temporary nothing"
26-
- uses: ./
27-
with:
28-
command: ls
29-
- uses: ./
30-
with:
31-
command: echo "test"
32-
env:
33-
VERCEL_TOKEN: "temporary nothing"
19+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
20+
VERCEL_DEPLOYMENT_URL: "https://github-action-deploy-on-vercel-example.vercel.app/"
21+
22+
- run: "echo \"Found deployment url: ${{ env.VERCEL_DEPLOYMENT_URL }}\""

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ yarn-error.log*
127127

128128
# Tmp files (cache, etc.)
129129
*.cache
130+
131+
.vercel

.idea/.gitignore

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jsLibraryMappings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 27 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<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-
[![Maintainability](https://api.codeclimate.com/v1/badges/9e073b5db2eec4c4e5c8/maintainability)](https://codeclimate.com/github/UnlyEd/github-action-store-variable/maintainability)
3-
[![Test Coverage](https://api.codeclimate.com/v1/badges/9e073b5db2eec4c4e5c8/test_coverage)](https://codeclimate.com/github/UnlyEd/github-action-store-variable/test_coverage)
2+
[![Maintainability](https://api.codeclimate.com/v1/badges/97a6022a22be785dd2ea/maintainability)](https://codeclimate.com/github/UnlyEd/github-action-deploy-on-vercel/maintainability)
3+
[![Test Coverage](https://api.codeclimate.com/v1/badges/97a6022a22be785dd2ea/test_coverage)](https://codeclimate.com/github/UnlyEd/github-action-deploy-on-vercel/test_coverage)
44

5-
![GitHub Action integration test](https://github.com/UnlyEd/github-action-store-variable/workflows/GitHub%20Action%20integration%20test/badge.svg)
6-
![GitHub Action build test](https://github.com/UnlyEd/github-action-store-variable/workflows/GitHub%20Action%20build%20test/badge.svg)
7-
![Update Code Climate test coverage](https://github.com/UnlyEd/github-action-store-variable/workflows/Update%20Code%20Climate%20test%20coverage/badge.svg)
5+
![GitHub Action integration test](https://github.com/UnlyEd/github-action-deploy-on-vercel/workflows/GitHub%20Action%20integration%20test/badge.svg)
6+
![GitHub Action build test](https://github.com/UnlyEd/github-action-deploy-on-vercel/workflows/GitHub%20Action%20build%20test/badge.svg)
7+
![Update Code Climate test coverage](https://github.com/UnlyEd/github-action-deploy-on-vercel/workflows/Update%20Code%20Climate%20test%20coverage/badge.svg)
88

99
# GitHub Action - Store variables between your jobs
1010

@@ -13,182 +13,62 @@
1313
```yaml
1414
name: 'GitHub Action code snippet'
1515
on:
16+
pull_request:
1617
push:
1718
branches:
1819
- '*'
20+
1921
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:
2323
runs-on: ubuntu-18.04
2424
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
3627
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 }}
4031

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 }}\""
5633
```
5734
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-
6235
## What does this GitHub Action do?
6336
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.
6538
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).
6740

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).
7642

7743
## Why/when should you use it?
7844

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.
8246

8347
### Action's API
8448

8549
#### Inputs
8650

8751
Name | Required | Default | Description
8852
--- | --- |--- |---
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
9256

9357
#### Outputs
9458

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**.
10060

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
18464

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.
18666

18767
## :hugs: Community examples :heart:
18868

18969
Here are a few community-powered examples, those are usually advanced use-cases!
19070

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!)_
19272

19373
---
19474

action.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
name: 'Deploy on Vercel'
22
description: 'Easily deploy your project on Vercel'
33
branding:
4-
#icon: bookmark #TODO
5-
#color: red
4+
icon: box
5+
color: gray-dark
66
inputs:
77
command:
8-
description: 'Command to execute to start vercel deployment'
8+
description: 'Command starting the vercel deployment'
99
required: true
10-
apply_domain_aliases:
11-
description: 'Enable alias feature in the vercel.json'
10+
applyDomainAliases:
11+
description: 'If true, will create Vercel aliases using the aliases specified in the vercel config file'
1212
required: false
1313
default: "true"
1414
failIfAliasNotLinked:
1515
description: 'If true, will throw an error (and crash CI) when there is an error about aliases link'
1616
required: false
1717
default: "false"
1818
outputs:
19-
deployment-url:
20-
description: "Url deployed"
19+
VERCEL_DEPLOYMENT_URL:
20+
description: "Full Vercel deployment url (parsed from the deployment logs), e.g: https://xxx.vercel.app"
21+
VERCEL_DEPLOYMENT_DOMAIN:
22+
description: "Url without the protocol declaration, e.g: xxx.vercel.app"
23+
VERCEL_ALIASES_ERROR:
24+
description: "(optional) Vercel errors during domain aliasing"
2125
runs:
2226
using: 'node12'
2327
main: 'lib/main.js'

examples/static-deployment/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vercel

examples/static-deployment/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<html>
2+
<h1>Deployment succeeded, deployed by <code>run-example-deployment</code> GitHub workflow.</h1>
3+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": 2,
3+
"name": "github-action-deploy-on-vercel-example",
4+
"scope": "team_qnVfSEVc2WwmOE1OYhZr4VST",
5+
"alias": [
6+
"github-action-deploy-on-vercel-example-alias.vercel.app",
7+
"deploy-on-vercel-example.vercel.app"
8+
]
9+
}

lib/vercel.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ const create_aliases = (deploymentUrl, customDeploymentFile, failIfAliasNotLinke
9999
core.debug(`Resolving alias promises`);
100100
const aliasesResponse = yield Promise.all(aliasCreationPromises);
101101
console.log(`Alias creation response: ${JSON.stringify(aliasesResponse)}`);
102-
if (aliasesResponse.filter(response => response.error)) {
102+
if (aliasesResponse.filter(response => response.error).length > 0) {
103103
const failedAliases = aliasesResponse.filter((response) => response.error).map((response) => response.error);
104104
const message = `Got following errors: ${JSON.stringify(failedAliases)}`;
105105
failIfAliasNotLinked ? core.setFailed(message) : core.warning(message);
106+
console.log(`Exporting this error...`);
107+
core.setOutput('VERCEL_ALIASES_ERROR', failedAliases);
106108
}
107109
for (const alias of aliasesResponse.filter(response => !response.error)) {
108110
console.log(`Created alias ${alias}`);
@@ -118,6 +120,10 @@ const create_aliases = (deploymentUrl, customDeploymentFile, failIfAliasNotLinke
118120
});
119121
const deploy = (command, deployAlias, failIfAliasNotLinked) => __awaiter(void 0, void 0, void 0, function* () {
120122
var _a, _b, _c;
123+
/**
124+
* Execute the command provided and store it into a variable
125+
* exec_command also displays the output
126+
*/
121127
const stdout = yield exec_command(command);
122128
/**
123129
* Parsing this huge output by using Regex match.

0 commit comments

Comments
 (0)