Skip to content

Commit

Permalink
feat(github-actions): detect rescript projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Rickard Natt och Dag committed Nov 12, 2020
1 parent 93abdb9 commit f57326c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
12 changes: 9 additions & 3 deletions src/commands/github_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@ use serde_json::json;
use std::fs;

pub fn run(no_npm: bool) -> Result<()> {
let has_bs_config = fs::metadata("bsconfig.json").is_ok();

if has_bs_config {
println!("Found ReScript project");
}

fs::create_dir_all(".github/workflows")?;

template::render(
include_str!("../templates/github_actions/release.yml"),
".github/workflows/release.yml",
Some(json!({ "no_npm": no_npm })),
Some(json!({ "noNpm": no_npm, "isRescript": has_bs_config })),
)?;
template::render(
include_str!("../templates/github_actions/pr_check.yml"),
".github/workflows/pr_check.yml",
None,
Some(json!({ "isRescript": has_bs_config })),
)?;
template::render(
include_str!("../templates/github_actions/.releaserc"),
".releaserc",
Some(json!({ "no_npm": no_npm })),
Some(json!({ "noNpm": no_npm })),
)?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/templates/github_actions/.releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
{{#unless no_npm}}"@semantic-release/npm", {{else}}["@semantic-release/npm", {
{{#unless noNpm}}"@semantic-release/npm", {{else}}["@semantic-release/npm", {
"npmPublish": false
}],{{/unless}}
"@semantic-release/git"
Expand Down
2 changes: 1 addition & 1 deletion src/templates/github_actions/pr_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Run tests and linting
run: |
npm ci
npm run lint --if-present
{{#unless isRescript}}npm run lint --if-present{{/unless}}{{#if isRescript}}npm run build{{/if}}
npm test
env:
CI: true
Expand Down
18 changes: 13 additions & 5 deletions src/templates/github_actions/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,29 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- name: Checkout code
uses: actions/checkout@v1
- name: Setup Node
uses: actions/setup-node@v1

- name: Run tests and linting
run: |
npm install
npm run lint --if-present
{{#unless isRescript}}npm run lint --if-present{{/unless}}{{#if isRescript}}npm run build{{/if}}
npm test
env:
CI: true

- name: Create release using semantic-release
run: npx semantic-release
uses: cycjimmy/semantic-release-action@v2
id: semantic
with:
semantic_version: 17.1.1
extra_plugins: |
@semantic-release/changelog@5.0.1
@semantic-release/git@9.0
env:
# GITHUB_TOKEN is added automatically by GitHub
GITHUB_TOKEN: {{{{raw}}}}${{ secrets.GITHUB_TOKEN }}{{{{/raw}}}}
{{#unless no_npm}}NPM_TOKEN: {{{{raw}}}}${{ secrets.NPM_TOKEN }}{{{{/raw}}}}{{/unless}}
{{#unless noNpm}}NPM_TOKEN: {{{{raw}}}}${{ secrets.NPM_TOKEN }}{{{{/raw}}}}{{/unless}}

0 comments on commit f57326c

Please sign in to comment.