Skip to content

Commit f81972e

Browse files
authored
initial commit (#1)
Signed-off-by: 20k-ultra <3946250+20k-ultra@users.noreply.github.com>
1 parent 07aecfa commit f81972e

File tree

2 files changed

+153
-1
lines changed

2 files changed

+153
-1
lines changed

README.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,82 @@
1-
## GitHub Action for Lagon
1+
# Lagon Action
2+
3+
Easily integrate [Lagon](https://lagon.dev) CLI into your Github workflows. Deploy new functions, retrieve a list of existing functions, promote functions, etc. This action supports any [arbitrary input](#other-commands) of what to do!
4+
5+
## Usage
6+
7+
Create the following workflow in your function's repository:
8+
9+
_./github/workflows/lagon.yml_
10+
11+
```yml
12+
name: Lagon
13+
14+
on:
15+
push:
16+
branches:
17+
- main
18+
19+
jobs:
20+
deploy:
21+
runs-on: ubuntu-latest
22+
name: Deploy
23+
steps:
24+
- uses: actions/checkout@v2
25+
- uses: lagonapp/github-action@latest
26+
with:
27+
lagon_token: ${{ secrets.LAGON_API_TOKEN }}
28+
- name: Log Function URL
29+
run: |
30+
url=$(grep -o 'https://[^[:space:]]*' lagon.output)
31+
echo "Function available at: $url"
32+
```
33+
34+
This will deploy your source code to the specified function after a commit is pushed into main.
35+
36+
_NOTE: Make sure the repository that gets checked out contains a `.lagon/config.json` file that specifies information such as the function_id and organization_id or pass in a config via the config input value mentioned below!_
37+
38+
#### Other commands
39+
40+
If you want to run a different command just specify it with the `command` input:
41+
42+
```bash
43+
with:
44+
lagon_token: ${{ secrets.LAGON_API_TOKEN }}
45+
command: ls
46+
```
47+
48+
See [CLI](https://docs.lagon.app/cli) docs for more commands.
49+
50+
## Inputs
51+
52+
Inputs are provided using the `with:` section of your workflow YML file.
53+
54+
| key | Description | Required | Default |
55+
| ----------- | ---------------------------- | -------- | ---------------------- |
56+
| lagon_token | Your Lagon API token | true | |
57+
| command | The Lagon CLI command to run | false | deploy --prod |
58+
| site_url | Specify Lagon API domain | false | https://dash.lagon.app |
59+
| config | Config file for function | false | |
60+
61+
`site_url` is used to specify a custom endpoint if you are using a self-hosted instance of Lagon.
62+
63+
`config` allows you to override a repositories existing config or maybe it never existed because you didn't want to commit it:
64+
65+
```bash
66+
with:
67+
lagon_token: ${{ secrets.LAGON_API_TOKEN }}
68+
config: |
69+
{
70+
"function_id": "${{ vars.lagon_function_id }}",
71+
"organization_id": "${{ vars.lagon_org_id }}",
72+
"index": "hello.ts",
73+
"client": null,
74+
"assets": null
75+
}
76+
```
77+
78+
This example is setting the function and org ID with [variables](https://docs.github.com/en/actions/learn-github-actions/variables#creating-configuration-variables-for-a-repository).
79+
80+
## Outputs
81+
82+
Since the action allows you to run any command, there are no outputs. Instead, the CLI stdout will be saved to a local file called `lagon.output`.

action.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: "Lagon CLI"
2+
description: "Easily integrate Lagon CLI operations into your Github workflow"
3+
branding:
4+
icon: code
5+
color: blue
6+
inputs:
7+
lagon_token:
8+
description: "Your Lagon API token"
9+
required: true
10+
command:
11+
description: 'The Lagon CLI command to run. For example: "deploy" - will publish your Function'
12+
required: false
13+
default: "deploy --prod"
14+
site_url:
15+
description: "Specify custom url for self-hosted Lagon instances"
16+
required: false
17+
default: "https://dash.lagon.app"
18+
config:
19+
description: "Pass in .lagon/config.json file for your function"
20+
required: false
21+
default: ""
22+
outputs:
23+
cli_stdout:
24+
description: "The raw stdout from the CLI command executed"
25+
value: ${{ steps.cli.outputs.cli_stdout }}
26+
runs:
27+
using: "composite"
28+
steps:
29+
- name: "Install Node.js"
30+
uses: actions/setup-node@v3
31+
with:
32+
node-version: 18
33+
34+
- name: "Install CLI"
35+
shell: bash
36+
run: |
37+
npm install --global @lagon/cli esbuild
38+
39+
- name: "Execute CLI"
40+
id: cli
41+
env:
42+
LAGON_TOKEN: ${{ inputs.lagon_token }}
43+
LAGON_COMMAND: ${{ inputs.command }}
44+
LAGON_URL: ${{ inputs.site_url }}
45+
LAGON_CONFIG: ${{ inputs.config }}
46+
shell: bash
47+
run: |
48+
echo "Configuring Lagon CLI..."
49+
if [[ -z "${LAGON_TOKEN}" ]]; then
50+
echo "LAGON_API_TOKEN input is not set"
51+
exit 1
52+
fi
53+
54+
# Setup config folders
55+
mkdir -p "$HOME/.lagon"
56+
57+
# Setup auth
58+
echo \{\"token\":\""${LAGON_TOKEN}"\",\"site_url\":\""${LAGON_URL}"\"\} | jq >"$HOME/.lagon/config.json"
59+
60+
# Setup lagon function config if one was provided
61+
if [[ -n "${LAGON_CONFIG}" ]]; then
62+
echo "LAGON_CONFIG variable set from environment...applying to local directory"
63+
mkdir -p .lagon
64+
echo "$LAGON_CONFIG" | jq >.lagon/config.json
65+
fi
66+
67+
# Run CLI
68+
echo "Executing CLI..."
69+
eval "lagon $LAGON_COMMAND" | tee lagon.output
70+
# Action is done!
71+
exit $?

0 commit comments

Comments
 (0)