Skip to content

Commit 2ccb786

Browse files
committed
feat(nx-fly-deployment-action): add automated fly deployments package
closed COD-110
1 parent aaab584 commit 2ccb786

36 files changed

+1947
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ npx create-nx-payload
3838

3939
### GitHub Actions
4040

41+
#### [`nx-fly-deployment-action`](packages/nx-fly-deployment-action)
42+
43+
GitHub action that brings automatic [Fly.io](https://fly.io) deployments to your [Nx](https://nx.dev) workspace.
44+
4145
#### [`nx-migrate-action`](packages/nx-migrate-action)
4246

4347
GitHub action that brings automatic [Nx](https://nx.dev) migrations to your workspace.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @github/local-action
2+
ACTIONS_STEP_DEBUG=true
3+
INPUT_DRY-RUN=true
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<p align="center">
2+
<br />
3+
<img width="200" src="../../assets/cdwr-cloud.png" alt="codeware sthlm logo">
4+
<br />
5+
<br />
6+
</p>
7+
8+
<h1 align='center'>Nx Fly Deployment Action</h1>
9+
10+
<p align='center'>
11+
GitHub action that brings automatic <a href='https://fly.io'>Fly.io</a> deployments to your <a href='https://nx.dev'>Nx</a> workspace.
12+
<br />
13+
<br />
14+
<a href='https://www.npmjs.com/package/@cdwr/nx-fly-deployment-action'><img src='https://img.shields.io/npm/v/@cdwr/nx-fly-deployment-action?label=npm%20version' alt='@cdwr/nx-fly-deployment-action npm'></a>
15+
&nbsp;
16+
<a href='https://opensource.org/licenses/MIT'><img src='https://img.shields.io/badge/License-MIT-green.svg' alt='MIT'></a>
17+
<br />
18+
<br />
19+
</p>
20+
21+
## Description
22+
23+
This action will manage deployments to [Fly.io](https://fly.io) of your [Nx](https://nx.dev) workspace applications.
24+
25+
## Usage
26+
27+
> [!IMPORTANT]
28+
> Using the action is currently limited to cloning this repository since the package isn't deployed according to action best practices.
29+
>
30+
> We have a monorepo and are considering other options to make the action available to other repositories.
31+
32+
```yaml
33+
- uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0
36+
37+
# Install dependencies and tools...
38+
# Build 'fly-deployment-action' package...
39+
40+
# Fly CLI must be installed
41+
- name: Install Fly CLI
42+
uses: superfly/flyctl-actions/setup-flyctl@master
43+
with:
44+
version: 0.3.45
45+
46+
# Let Nx analyze which projects are affected and hence will be deployed
47+
- name: Analyze affected projects to deploy
48+
uses: nrwl/nx-set-shas@v4
49+
with:
50+
set-environment-variables-for-job: true
51+
52+
- name: Run Nx Fly Deployment
53+
uses: ./packages/nx-fly-deployment-action
54+
with:
55+
fly-api-token: ${{ secrets.FLY_API_TOKEN }}
56+
token: ${{ secrets.GITHUB_TOKEN }}
57+
```
58+
59+
### Outputs
60+
61+
The action will output the following variables:
62+
63+
- `environment`: The environment used for deployment.
64+
- `destroyed`: A list of project names that were destroyed.
65+
- `skipped`: A list of project names that were skipped for some reason.
66+
- `deployed`: JSON object containing the deployed project names and their urls.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: 'Nx Fly Deployment'
2+
3+
description: >
4+
Automatically manage deployment of your Nx applications to Fly.io.
5+
6+
inputs:
7+
fly-api-token:
8+
description: >
9+
Authenticate using a Fly API access token or with setting the `FLY_API_TOKEN`
10+
environment variable.
11+
fly-org:
12+
description: >
13+
The target organisation for your deployed applications.
14+
Defaults to your personal organisation.
15+
fly-region:
16+
description: >
17+
The target region for your deployed applications.
18+
Defaults to auto-detect the fastest location.
19+
main-branch:
20+
description: >
21+
The main branch name.
22+
Defaults to the default branch of the repository.
23+
token:
24+
description: >
25+
The token to use for repository authentication.
26+
For example `GITHUB_TOKEN`.
27+
required: true
28+
29+
outputs:
30+
environment:
31+
description: >
32+
The environment used for deployment.
33+
destroyed:
34+
description: >
35+
A list of project names that were destroyed.
36+
skipped:
37+
description: >
38+
A list of project names that were skipped for some reason.
39+
deployed:
40+
description: >
41+
JSON object containing the deployed project names and their urls.
42+
43+
runs:
44+
using: 'node20'
45+
main: '../../dist/packages/nx-fly-deployment-action/action.cjs'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const baseConfig = require('../../eslint.config.js');
2+
3+
module.exports = [
4+
...baseConfig,
5+
{
6+
files: ['**/*.json'],
7+
rules: {
8+
'@nx/dependency-checks': [
9+
'error',
10+
{
11+
ignoredDependencies: ['@cdwr/core', '@cdwr/fly-node'],
12+
ignoredFiles: [
13+
'{projectRoot}/eslint.config.{js,cjs,mjs}',
14+
'{projectRoot}/vite.config.{js,ts,mjs,mts}'
15+
]
16+
}
17+
]
18+
},
19+
languageOptions: {
20+
parser: require('jsonc-eslint-parser')
21+
}
22+
}
23+
];
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "@cdwr/nx-fly-deployment-action",
3+
"version": "0.0.1",
4+
"description": "The Nx Fly Deployment Action will manage your deployments to fly.io.",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/codeware-sthlm/codeware.git",
8+
"directory": "packages/nx-fly-deployment-action"
9+
},
10+
"author": {
11+
"name": "Codeware Sthlm",
12+
"email": "hello@codeware.se",
13+
"url": "https://codeware.se"
14+
},
15+
"license": "MIT",
16+
"keywords": [
17+
"Automation",
18+
"GitHub Actions",
19+
"Deploy",
20+
"Fly.io",
21+
"Nx"
22+
],
23+
"publishConfig": {
24+
"access": "public"
25+
},
26+
"dependencies": {
27+
"@actions/core": "^1.11.1",
28+
"@actions/exec": "^1.1.1",
29+
"@actions/github": "^6.0.0",
30+
"@nx/devkit": "20.x",
31+
"@octokit/webhooks-types": "^7.6.1",
32+
"zod": "^3.23.8"
33+
},
34+
"type": "module",
35+
"exports": {
36+
".": {
37+
"types": "./src/index.d.ts",
38+
"import": "./index.js",
39+
"require": "./index.cjs"
40+
}
41+
},
42+
"types": "./src/index.d.ts",
43+
"main": "./index.js",
44+
"module": "./index.js"
45+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "nx-fly-deployment-action",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "packages/nx-fly-deployment-action/src",
5+
"projectType": "library",
6+
"tags": ["scope:nx-fly-deployment-action", "type:action"],
7+
"targets": {
8+
"build": {
9+
"executor": "@nx/esbuild:esbuild",
10+
"options": {
11+
"assets": [
12+
"packages/nx-fly-deployment-action/*.md",
13+
"packages/nx-fly-deployment-action/action.yml"
14+
],
15+
"additionalEntryPoints": [
16+
"packages/nx-fly-deployment-action/src/action.ts"
17+
],
18+
"format": ["cjs", "esm"]
19+
}
20+
},
21+
"act": {
22+
"command": "act schedule --env-file .env.act -j nx-fly-deployment"
23+
}
24+
}
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as main from './lib/main';
2+
3+
// Mock the action's entrypoint
4+
const runMock = vi.spyOn(main, 'run').mockResolvedValue();
5+
6+
describe('index action', () => {
7+
it('should call run when imported', async () => {
8+
await import('./action');
9+
expect(runMock).toHaveBeenCalled();
10+
});
11+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { run } from './lib/main';
2+
3+
run();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './lib/fly-deployment';
2+
export * from './lib/main';

0 commit comments

Comments
 (0)