Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): add custom scripts plugin #17

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(web): inhert script process logs if verbose or debug
eahefnawy committed Sep 24, 2024
commit 7ab434d6aec96ad5b7349ba7734fb08f3d4c3685
10 changes: 1 addition & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
name: Deploy main branch

on:
push:
branches:
- main
pull_request:
branches:
- main
pull_request_target:
types:
- closed

jobs:
deploy:
name: deploy
if: github.event_name != 'pull_request_target' || github.event.pull_request.merged != true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
@@ -35,14 +28,13 @@ jobs:
- name: Serverless Deploy
uses: serverless/github-action@v4
with:
args: deploy --stage ${{ github.event.pull_request.number && 'pr-${{ github.event.pull_request.number }}' || 'prod' }}
args: deploy --stage pr-${{ github.event.pull_request.number }}
env:
SERVERLESS_LICENSE_KEY: ${{ secrets.SERVERLESS_LICENSE_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
remove:
name: remove
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
13 changes: 11 additions & 2 deletions website/scripts.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { execSync } from "child_process";

class Scripts {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add inline comments to provide more context for users who might not be familiar with plugins. A few things to cover...

  • Why it exists - to run custom scripts, which we need to run the build script at deploy time, with support for variable resolution from framework, as well as proper stdio handling.
  • How this works - it runs because it's included as a plugin in serverless.yml, and how hooks work.

constructor(serverless) {
constructor(serverless, options, utils) {
this.serverless = serverless;
this.options = options;
this.utils = utils;

this.commands = {};
this.hooks = {};

@@ -53,7 +56,13 @@ class Scripts {
}

execute(command) {
execSync(command, { stdio: ["ignore", "ignore", "inherit"] });
let stdio = ["ignore", "ignore", "inherit"];

if (this.options.verbose || this.options.debug) {
stdio = "inherit";
}

execSync(command, { stdio });
}
}