Skip to content
This repository was archived by the owner on Mar 15, 2026. It is now read-only.

Commit d6b0b6d

Browse files
committed
initial commit
Signed-off-by: 20k-ultra <3946250+20k-ultra@users.noreply.github.com>
1 parent 07aecfa commit d6b0b6d

4 files changed

Lines changed: 237 additions & 1 deletion

File tree

README.md

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,89 @@
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@main
26+
with:
27+
lagon_token: ${{ secrets.LAGON_API_TOKEN }}
28+
```
29+
30+
This will deploy your source code to the specified function after a commit is pushed into main.
31+
32+
_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!_
33+
34+
#### Other commands
35+
36+
If you want to run a different command just specify it with the `command` input:
37+
38+
```bash
39+
with:
40+
lagon_token: ${{ secrets.LAGON_API_TOKEN }}
41+
command: "promote claxnlc230738q5pa7iximskm ./my-project"
42+
```
43+
44+
See [CLI](https://docs.lagon.app/cli) docs for more commands.
45+
46+
## Inputs
47+
48+
Inputs are provided using the `with:` section of your workflow YML file.
49+
50+
| key | Description | Required | Default |
51+
| ----------- | ---------------------------- | -------- | ---------------------- |
52+
| lagon_token | Your Lagon API token | true | |
53+
| command | The Lagon CLI command to run | false | deploy --prod |
54+
| site_url | Specify Lagon API domain | false | https://dash.lagon.app |
55+
56+
`site_url` is used to specify a custom endpoint if you are using a self-hosted instance of Lagon.
57+
58+
## Outputs
59+
60+
| key | Description | Nullable |
61+
| --- | ----------- | -------- |
62+
| | | |
63+
64+
No outputs for now... not sure what the CLI can output, function hash ?
65+
66+
## Developing
67+
68+
Install [act](https://github.com/nektos/act) then push your action changes to a branch on Github if you want to test the changes you made. Unfortunately, you have to push your changes to Github for this test runner to work.
69+
70+
**Make sure to export `LAGON_API_TOKEN` so the action can configure the CLI! This is normally populated by Github.**
71+
72+
Once you have pushed the changes you want to test you can now run it locally with the provided [test.sh](/test.sh) script like so:
73+
74+
```bash
75+
# Usage: ./test.sh -f path_to_function [-r repo, -c command, -s site_url]
76+
77+
# Test the main branch with a local function project
78+
./test.sh -f ~/Projects/lagon-function
79+
80+
# Test a development branch
81+
./test.sh -r lagonapp/github-action@my-dev-branch -f ~/Projects/lagon-function
82+
83+
# You can also specify the command and site_url
84+
# See the inputs table for more info on the commands
85+
./test.sh -r lagonapp/github-action@my-dev-branch \
86+
-f ~/Projects/lagon-function \
87+
-c "ls" \
88+
-s "https://lagon.mysite.io"
89+
```

action.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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"
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+
runs:
19+
using: "composite"
20+
steps:
21+
- name: "Install Node.js"
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: 18
25+
cache: npm
26+
27+
- name: "Install CLI"
28+
run: npm install --global @lagon/cli esbuild
29+
30+
- name: "Execute CLI"
31+
env:
32+
LAGON_TOKEN: ${{ inputs.lagon_token }}
33+
LAGON_COMMAND: ${{ inputs.command }}
34+
LAGON_URL: ${{ inputs.site_url }}
35+
shell: bash
36+
run: |
37+
# Setup config folder
38+
mkdir -p ~/.lagon
39+
# Setup auth
40+
echo \{\"token\":\""${LAGON_TOKEN}"\",\"site_url\":\""${LAGON_URL}"\"\} >~/.lagon/config.json
41+
# Run CLI
42+
eval lagon "$LAGON_COMMAND"

test.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
function cleanup {
5+
if [[ -n "${test_dir+x}" ]]; then
6+
rm -rf "$test_dir"
7+
fi
8+
}
9+
10+
# Register the cleanup function to run on exit or interrupt
11+
trap cleanup EXIT INT
12+
13+
command="deploy --prod"
14+
site_url="https://dash.lagon.app"
15+
action_repo="lagonapp/github-action@main"
16+
function_path=
17+
18+
# Parse inputs
19+
while getopts ":c:s:r:f:" opt; do
20+
case $opt in
21+
c)
22+
# Optional set the `command` input
23+
command="$OPTARG"
24+
;;
25+
s)
26+
# Optionally set the `site_url` input
27+
site_url="$OPTARG"
28+
;;
29+
r)
30+
# This tells act which lagon-action to run
31+
action_repo="$OPTARG"
32+
;;
33+
f)
34+
# This is the folder that the action will run with (build and deploy)
35+
function_path="$OPTARG"
36+
;;
37+
\?)
38+
echo "Invalid option -$OPTARG" >&2
39+
;;
40+
esac
41+
done
42+
43+
# Check that required options are set
44+
if [ -z "$function_path" ]; then
45+
echo "Usage: $0 -f path_to_function [-r repo, -c command, -s site_url]" >&2
46+
exit 1
47+
fi
48+
49+
if ! [ -v LAGON_API_TOKEN ]; then
50+
echo "You need to export LAGON_API_TOKEN so the action can authenticate the CLI!" >&2
51+
exit 1
52+
fi
53+
#
54+
# Make sure the specified directory exists
55+
if [ ! -d "$function_path" ]; then
56+
echo "Directory '$function_path' does not exist" >&2
57+
exit 1
58+
fi
59+
60+
# Make sure the project is a git repo since act will fail
61+
if [ ! -d "$function_path/.git" ]; then
62+
echo "Project '$function_path' must be a git initialized repository" >&2
63+
exit 1
64+
fi
65+
66+
# Create test directory to simulate a repository
67+
test_dir="/tmp/lagon-action-tester"
68+
mkdir -p "$test_dir"
69+
# Create a modified copy of the workflow_test.yml file using the provided repo url
70+
sed "s!_ACTION_REPO_!$action_repo!g" "$(pwd)/workflow_test.yml" >"$test_dir/test.yml"
71+
# Symlink project's .git folder so the checkout step works
72+
ln -sn "$function_path/.git" "$test_dir/.git"
73+
74+
# Clear action cache so new changes are always picked up
75+
rm -r ~/.cache/act/"$(echo "$action_repo" | sed 's/\//-/g')"
76+
77+
printf "Config: {\n action: \"%s\",\n function_source: \"%s\",\n command: \"%s\",\n site_url: \"%s\"\n}\n" "$action_repo" "$function_path" "$command" "$site_url"
78+
# run the test workflow with the workflow_dispatch event in the simulated repo (test_dir) and specify a lagon secret.
79+
# The secret is otherwise set by github when the workflow runs.
80+
if ! act --input COMMAND="$command" --input SITE_URL="$site_url" workflow_dispatch -C "$test_dir" -W test.yml -s "LAGON_API_TOKEN=$LAGON_API_TOKEN"; then
81+
exit $?
82+
fi
83+
84+
# Clean up the test directory
85+
cleanup

workflow_test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: lagon
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
command:
7+
required: true
8+
site_url:
9+
required: true
10+
11+
jobs:
12+
deploy:
13+
runs-on: ubuntu-latest
14+
name: Deploy
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: _ACTION_REPO_ # This gets updated by the test.sh script
18+
with:
19+
lagon_token: ${{ secrets.LAGON_API_TOKEN }}
20+
command: ${{ github.event.inputs.command }} # github.event.inputs is only for workflow_dispatch events
21+
site_url: ${{ github.event.inputs.site_url }} # github.event.inputs is only for workflow_dispatch events

0 commit comments

Comments
 (0)