-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add npm and yarn based build auto-generator
- Loading branch information
Showing
6 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package generator | ||
|
||
import "fmt" | ||
|
||
const _setupNodeJsTask = ` | ||
- name: "Setup Node.js for %s" | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "latest" | ||
cache: "npm" | ||
cache-dependency-path: "%s/package-lock.json" | ||
` | ||
|
||
const _buildNpmTask = ` | ||
- name: "Build %s using NPM" | ||
working-directory: %s | ||
run: npm install && npm run build | ||
` | ||
|
||
func generateBuildNpmYaml(repoDir string) (*string, error) { | ||
dirs, err := getDirsContaining(repoDir, "package-lock.json") | ||
if err != nil { | ||
return nil, err | ||
} | ||
str := _buildNpmTemplate | ||
for _, dir := range dirs { | ||
str += fmt.Sprintf(_setupNodeJsTask, dir, dir) | ||
str += fmt.Sprintf(_buildNpmTask, dir, dir) | ||
} | ||
return &str, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package generator | ||
|
||
import "fmt" | ||
|
||
const _setupYarnTask = ` | ||
- name: "Setup Node.js for %s" | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "latest" | ||
cache: "yarn" | ||
cache-dependency-path: "%s/yarn.lock" | ||
` | ||
|
||
const _buildYarnTask = ` | ||
- name: "Build %s using Yarn" | ||
working-directory: %s | ||
run: yarn && yarn build | ||
` | ||
|
||
func generateBuildYarnYaml(repoDir string) (*string, error) { | ||
dirs, err := getDirsContaining(repoDir, "yarn.lock") | ||
if err != nil { | ||
return nil, err | ||
} | ||
str := _buildYarnTemplate | ||
for _, dir := range dirs { | ||
str += fmt.Sprintf(_setupYarnTask, dir, dir) | ||
str += fmt.Sprintf(_buildYarnTask, dir, dir) | ||
} | ||
return &str, nil | ||
} |
27 changes: 27 additions & 0 deletions
27
src/gabo/internal/generator/data/build-npm-incomplete.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
name: Build Node.js package(s) | ||
|
||
on: # yamllint disable-line rule:truthy | ||
push: | ||
branches: [main, master] | ||
paths: | ||
- "**/package-lock.json" | ||
- ".github/workflows/build-npm.yaml" | ||
pull_request: | ||
branches: [main, master] | ||
paths: | ||
- "**/package-lock.json" | ||
- ".github/workflows/build-npm.yaml" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
buildNpm: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 |
27 changes: 27 additions & 0 deletions
27
src/gabo/internal/generator/data/build-yarn-incomplete.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
name: Build Node.js package(s) | ||
|
||
on: # yamllint disable-line rule:truthy | ||
push: | ||
branches: [main, master] | ||
paths: | ||
- "**/yarn-lock.json" | ||
- ".github/workflows/build-yarn.yaml" | ||
pull_request: | ||
branches: [main, master] | ||
paths: | ||
- "**/yarn-lock.json" | ||
- ".github/workflows/build-yarn.yaml" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
buildYarn: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters