@sdeverywhere/plugin-deploy 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +215 -0
- package/dist/index.cjs +506 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +77 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +480 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Climate Interactive / New Venture Fund
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# @sdeverywhere/plugin-deploy
|
|
2
|
+
|
|
3
|
+
This package provides a build plugin that simplifies the process of deploying an [SDEverywhere](https://github.com/climateinteractive/SDEverywhere)-generated app to a web server.
|
|
4
|
+
|
|
5
|
+
Currently this plugin supports deploying to [GitHub Pages](https://docs.github.com/en/pages), a free static site hosting service that is connected to a given GitHub repository.
|
|
6
|
+
Support for other hosting services (e.g., [GitLab Pages](https://docs.gitlab.com/user/project/pages/), [AWS S3](https://aws.amazon.com/s3/)) is on the roadmap.
|
|
7
|
+
|
|
8
|
+
## Quick Start
|
|
9
|
+
|
|
10
|
+
The best way to get started with SDEverywhere is to follow the [Quick Start](https://github.com/climateinteractive/SDEverywhere#quick-start) instructions.
|
|
11
|
+
If you follow those instructions, the `@sdeverywhere/plugin-deploy` package will be added to your project automatically, in which case you can skip the next section and jump straight to the ["Usage"](#usage) section below.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
# npm
|
|
17
|
+
npm install --save-dev @sdeverywhere/plugin-deploy
|
|
18
|
+
|
|
19
|
+
# pnpm
|
|
20
|
+
pnpm add -D @sdeverywhere/plugin-deploy
|
|
21
|
+
|
|
22
|
+
# yarn
|
|
23
|
+
yarn add -D @sdeverywhere/plugin-deploy
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
_Note:_ If you followed the "Quick Start" instructions above and/or are using one of the standard project templates provided by SDEverywhere, the `sde.config.js` file should already be set up to use `plugin-deploy`.
|
|
29
|
+
Reading these instructions can still be helpful if you are setting up a project manually or want to understand how `plugin-deploy` can be integrated into your project.
|
|
30
|
+
|
|
31
|
+
To get started:
|
|
32
|
+
|
|
33
|
+
1. Add `@sdeverywhere/plugin-deploy` as a project "dev" dependency:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
cd your-model-project
|
|
37
|
+
npm install --save-dev @sdeverywhere/plugin-deploy
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
2. Update your `sde.config.js` file to use `plugin-deploy`. Make sure that `deployPlugin` is the last step in the `plugins` array:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import { deployPlugin } from '@sdeverywhere/plugin-deploy'
|
|
44
|
+
|
|
45
|
+
export async function config() {
|
|
46
|
+
return {
|
|
47
|
+
// ...
|
|
48
|
+
|
|
49
|
+
plugins: [
|
|
50
|
+
// ...
|
|
51
|
+
|
|
52
|
+
// Make sure that `deployPlugin` is the last step, since it depends on the output of
|
|
53
|
+
// earlier plugins
|
|
54
|
+
deployPlugin({
|
|
55
|
+
// Include options here if needed
|
|
56
|
+
})
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
3. Update your GitHub Actions workflow to run `sde bundle`.
|
|
63
|
+
|
|
64
|
+
## How It Works
|
|
65
|
+
|
|
66
|
+
### Overview
|
|
67
|
+
|
|
68
|
+
At a high level, this plugin has two main functions:
|
|
69
|
+
|
|
70
|
+
- It copies build products (e.g., your app, model-check bundle, model-check report, etc) to an ideal structure in the `sde-staged` folder.
|
|
71
|
+
- It stores the contents of the `sde-staged` folder in a separate ("orphan") `artifacts` branch in your Git repository.
|
|
72
|
+
|
|
73
|
+
Once the build products are added to the `artifacts` branch, they can be published to GitHub Pages in a GitHub Actions workflow that runs each time you push changes to your repository (see "Deploying in GitHub Actions" below for an example).
|
|
74
|
+
|
|
75
|
+
### The `sde-staged` directory
|
|
76
|
+
|
|
77
|
+
This plugin creates the `sde-staged` directory in your current branch and copies your app, model-check files, etc to that directory.
|
|
78
|
+
The `sde-staged` directory structure is as follows:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
sde-staged/
|
|
82
|
+
├── app
|
|
83
|
+
| ├── index.html # App entrypoint
|
|
84
|
+
| ├── assets/ # App assets
|
|
85
|
+
└── extras/
|
|
86
|
+
├── check-bundle.js # The model-check bundle file
|
|
87
|
+
└── check-compare-to-base/ # The model-check report
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### The `artifacts` branch and directory
|
|
91
|
+
|
|
92
|
+
Once the `sde-staged` directory is populated, this plugin folds the contents of `sde-staged` into the `artifacts` branch, which contains build artifacts for all branches that have been built.
|
|
93
|
+
The `artifacts` directory structure is as follows:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
artifacts/
|
|
97
|
+
├── index.html # Top-level index.html file
|
|
98
|
+
├── latest/
|
|
99
|
+
| ├── index.html # Main branch app
|
|
100
|
+
| ├── assets/ # Main branch assets
|
|
101
|
+
├── branch/
|
|
102
|
+
| ├── main/
|
|
103
|
+
| │ ├── app/ # Main branch app files
|
|
104
|
+
| │ └── extras/ # Main branch check bundles and reports
|
|
105
|
+
| ├── chris/1234-test/
|
|
106
|
+
| │ ├── app/ # Feature branch app files
|
|
107
|
+
| │ └── extras/ # Feature branch check bundles and reports
|
|
108
|
+
| └── feature/new-ui/
|
|
109
|
+
| ├── app/ # Feature branch app files
|
|
110
|
+
| └── extras/ # Feature branch check bundles and reports
|
|
111
|
+
└── metadata/
|
|
112
|
+
├── bundles.json # Listing of available bundles
|
|
113
|
+
└── index.json # Listing of available branch builds
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The top-level `index.html` file and `metadata` directory are updated with each build:
|
|
117
|
+
|
|
118
|
+
- The `index.html` file provides a convenient overview of the available branch build links that can be accessed during development of your model.
|
|
119
|
+
- The `metadata/index.json` file is used to keep track of all available branch builds and is used to create the top-level `index.html` file.
|
|
120
|
+
- The `metadata/bundles.json` file is used to keep track of all available bundles, mainly for use by the model-check tool, which allows selecting any available bundle.
|
|
121
|
+
|
|
122
|
+
### Deploying in GitHub Actions
|
|
123
|
+
|
|
124
|
+
Once the `artifacts` branch is updated, the `artifacts` directory can be published to GitHub Pages to make the entire directory structure available at the public URL.
|
|
125
|
+
|
|
126
|
+
The easiest way to deploy automatically is to create a GitHub Actions workflow that runs every time you push changes to your repository.
|
|
127
|
+
See below for an example workflow, which you can add to `.github/workflows/build.yaml` in your project.
|
|
128
|
+
|
|
129
|
+
_Note:_ If you followed the "Quick Start" instructions above and are using one of the standard project templates provided by SDEverywhere, the template should already contain a `.github/workflows/build.yaml` file.
|
|
130
|
+
If so, your project is already set up to deploy to GitHub Pages.
|
|
131
|
+
|
|
132
|
+
<details>
|
|
133
|
+
<summary>Click to show example GitHub Actions workflow</summary>
|
|
134
|
+
|
|
135
|
+
```yaml
|
|
136
|
+
#
|
|
137
|
+
# This workflow builds the app and model-check reports, stores them in the `artifacts` branch,
|
|
138
|
+
# then deploys the updated `artifacts` directory to GitHub Pages.
|
|
139
|
+
#
|
|
140
|
+
|
|
141
|
+
name: Build
|
|
142
|
+
|
|
143
|
+
on:
|
|
144
|
+
# Run this workflow on every push to any branch except the special `artifacts` branch
|
|
145
|
+
push:
|
|
146
|
+
branches:
|
|
147
|
+
- '**'
|
|
148
|
+
- '!artifacts'
|
|
149
|
+
# Allow for running this workflow manually from the Actions tab
|
|
150
|
+
workflow_dispatch:
|
|
151
|
+
|
|
152
|
+
# Set the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
|
|
153
|
+
permissions:
|
|
154
|
+
# Allow pushing to the `artifacts` branch
|
|
155
|
+
contents: write
|
|
156
|
+
# Allow deployment to GitHub Pages
|
|
157
|
+
pages: write
|
|
158
|
+
id-token: write
|
|
159
|
+
|
|
160
|
+
# Allow one concurrent build
|
|
161
|
+
concurrency:
|
|
162
|
+
group: 'build'
|
|
163
|
+
|
|
164
|
+
jobs:
|
|
165
|
+
build:
|
|
166
|
+
environment:
|
|
167
|
+
name: github-pages
|
|
168
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
169
|
+
runs-on: ubuntu-latest
|
|
170
|
+
steps:
|
|
171
|
+
- name: Check out current branch
|
|
172
|
+
uses: actions/checkout@v5
|
|
173
|
+
with:
|
|
174
|
+
# Fetch full history for `artifacts` branch operations
|
|
175
|
+
fetch-depth: 0
|
|
176
|
+
|
|
177
|
+
- name: Set up Node
|
|
178
|
+
uses: actions/setup-node@v4
|
|
179
|
+
with:
|
|
180
|
+
node-version: 22
|
|
181
|
+
cache: 'npm'
|
|
182
|
+
|
|
183
|
+
- name: Install dependencies
|
|
184
|
+
run: npm ci
|
|
185
|
+
|
|
186
|
+
- name: Build
|
|
187
|
+
env:
|
|
188
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
189
|
+
run: ./scripts/ci-build.js
|
|
190
|
+
|
|
191
|
+
- name: Check out artifacts branch
|
|
192
|
+
run: git checkout artifacts
|
|
193
|
+
|
|
194
|
+
- name: Set up GitHub Pages
|
|
195
|
+
uses: actions/configure-pages@v5
|
|
196
|
+
|
|
197
|
+
- name: Upload GitHub Pages artifacts
|
|
198
|
+
uses: actions/upload-pages-artifact@v4
|
|
199
|
+
with:
|
|
200
|
+
path: './artifacts'
|
|
201
|
+
|
|
202
|
+
- name: Deploy to GitHub Pages
|
|
203
|
+
id: deployment
|
|
204
|
+
uses: actions/deploy-pages@v4
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
</details>
|
|
208
|
+
|
|
209
|
+
## Documentation
|
|
210
|
+
|
|
211
|
+
API documentation (for plugin configuration options) is available in the [`docs`](./docs/index.md) directory.
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
SDEverywhere is distributed under the MIT license. See `LICENSE` for more details.
|