Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions .github/workflows/deploy-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ jobs:
with:
compile_binary: 'true'
github_token: ${{ secrets.github_token }}
get_latest_release_current_branch: deno run --allow-all --quiet index.ts shebang https://github.com/levibostian/decaf-script-github-releases-release-branch.git/shebang.sh@0.2.0 get --release-branch latest
get_next_release_version: deno run --allow-all --quiet index.ts shebang https://github.com/levibostian/decaf-script-conventional-commits.git/shebang.sh@0.3.1
get_latest_release_current_branch: decaf shebang https://github.com/levibostian/decaf-script-github-releases-release-branch.git/shebang.sh@put-root-dir-env-var-in-input get --release-branch latest
get_next_release_version: decaf shebang https://github.com/levibostian/decaf-script-conventional-commits.git/shebang.sh@0.3.1
deploy: |
OUTPUT_FILE_NAME=dist/bin-x86_64-Linux DENO_TARGET=x86_64-unknown-linux-gnu deno task compile
OUTPUT_FILE_NAME=dist/bin-aarch64-Linux DENO_TARGET=aarch64-unknown-linux-gnu deno task compile
OUTPUT_FILE_NAME=dist/bin-x86_64-Darwin DENO_TARGET=x86_64-apple-darwin deno task compile
OUTPUT_FILE_NAME=dist/bin-aarch64-Darwin DENO_TARGET=aarch64-apple-darwin deno task compile
deno run --allow-all --quiet index.ts shebang https://github.com/levibostian/decaf-script-git.git/shebang.sh@0.3.0 merge-into-release-branch --release-branch latest
decaf shebang https://github.com/levibostian/decaf-script-git.git/shebang.sh@put-root-dir-env-var-in-input merge-into-release-branch --release-branch latest
echo "{{nextVersionName}}" > version.txt
cat version.txt
deno run --allow-all --quiet index.ts shebang https://github.com/levibostian/decaf-script-git.git/shebang.sh@0.3.0 commit-and-push --add version.txt
deno run --allow-all --quiet index.ts shebang https://github.com/levibostian/decaf-script-github-releases-release-branch.git/shebang.sh@0.2.0 set-github-release-assets dist/bin-x86_64-Linux#x86_64-unknown-linux-gnu dist/bin-aarch64-Linux#aarch64-unknown-linux-gnu dist/bin-x86_64-Darwin#x86_64-apple-darwin dist/bin-aarch64-Darwin#aarch64-apple-darwin
deno run --allow-all --quiet index.ts shebang https://github.com/levibostian/decaf-script-github-releases-release-branch.git/shebang.sh@0.2.0 set --release-branch latest
decaf shebang https://github.com/levibostian/decaf-script-git.git/shebang.sh@put-root-dir-env-var-in-input commit-and-push --add version.txt
decaf shebang https://github.com/levibostian/decaf-script-github-releases-release-branch.git/shebang.sh@put-root-dir-env-var-in-input set-github-release-assets dist/bin-x86_64-Linux#x86_64-unknown-linux-gnu dist/bin-aarch64-Linux#aarch64-unknown-linux-gnu dist/bin-x86_64-Darwin#x86_64-apple-darwin dist/bin-aarch64-Darwin#aarch64-apple-darwin
decaf shebang https://github.com/levibostian/decaf-script-github-releases-release-branch.git/shebang.sh@put-root-dir-env-var-in-input set --release-branch latest
20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ You will follow this pattern for all 3 of your deployment scripts. Now, let's be

> **Writing your scripts using Node.js, Bun, or Deno?:** Use the [decaf SDK](https://github.com/levibostian/decaf-sdk-deno/) to make writing your step scripts easier!

> Tip: Use the `current_working_directory` option to run all commands from a subdirectory (e.g., `current_working_directory: "./deployment"`). This keeps deployment scripts and dependencies separate from your application code. decaf also sets the `DECAF_ROOT_WORKING_DIRECTORY` environment variable to the root of your repository (where decaf is executed from), so you can change back to the root directory in your script.
> Tip: Use the `current_working_directory` option to run all commands from a subdirectory (e.g., `current_working_directory: "./deployment"`). This keeps deployment scripts and dependencies separate from your application code. decaf also passes a `gitRootDirectory` input value to your step scripts containing the root of your repository (where decaf is executed from), so you can change back to the root directory in your script.
>

### Create a shebang file to run your script
Expand All @@ -169,22 +169,7 @@ The `mise exec --` part is a convenient way to install `node` if it's not alread

Then, in order to run your script, use the built-in decaf shebang command: `decaf shebang <git-url>/<file>@<ref> [args...]`. Example: `decaf shebang git@github.com/levibostian/decaf-script-major-tag.git/run.ts@0.13.0 --commit-sha $(git rev-parse HEAD) --tag-prefix v` (here, `run.ts` is the shebang file that runs the actual script in the repo).

> **Running scripts against the codebase:** The shebang script runs in the cloned repo's directory so it can resolve its own relative imports. If your script needs to operate on the codebase at the project root (e.g., reading/writing files in the user's project), use the `DECAF_ROOT_WORKING_DIRECTORY` environment variable to change back to the project root:
>
> ```typescript
> // TypeScript/Deno
> Deno.chdir(Deno.env.get("DECAF_ROOT_WORKING_DIRECTORY")!);
> ```
>
> ```javascript
> // JavaScript/Node
> process.chdir(process.env.DECAF_ROOT_WORKING_DIRECTORY);
> ```
>
> ```bash
> # Bash
> cd "$DECAF_ROOT_WORKING_DIRECTORY"
> ```
> **Running scripts against the codebase:** The shebang script runs in the cloned repo's directory so it can resolve its own relative imports. If your script needs to operate on the codebase at the project root (e.g., reading/writing files in the user's project), use the `gitRootDirectory` input value to change back to the project root.

### Deployment script 1: Get latest release version

Expand All @@ -201,6 +186,7 @@ decaf provides your script with the following input data:
"gitCurrentBranch": "main",
"gitRepoOwner": "your-org",
"gitRepoName": "your-repo",
"gitRootDirectory": "/path/to/your/project",
"testMode": false
}
```
Expand Down
3 changes: 3 additions & 0 deletions deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Want to learn more about me? Visit the docs --> https://github.com/levibostian/d
gitCurrentBranch: currentBranch,
gitRepoOwner: owner,
gitRepoName: repo,
gitRootDirectory: git.getDirectory(),
testMode: runInTestMode,
gitCommitsCurrentBranch,
gitCommitsAllLocalBranches,
Expand Down Expand Up @@ -220,6 +221,7 @@ Want to learn more about me? Visit the docs --> https://github.com/levibostian/d
gitCurrentBranch: currentBranch,
gitRepoOwner: owner,
gitRepoName: repo,
gitRootDirectory: git.getDirectory(),
testMode: runInTestMode,
gitCommitsSinceLastRelease: listOfCommits,
lastRelease,
Expand Down Expand Up @@ -274,6 +276,7 @@ Want to learn more about me? Visit the docs --> https://github.com/levibostian/d
gitCurrentBranch: currentBranch,
gitRepoOwner: owner,
gitRepoName: repo,
gitRootDirectory: git.getDirectory(),
testMode: runInTestMode,
gitCommitsCurrentBranch: gitCommitsCurrentBranchAfterDeploy,
gitCommitsAllLocalBranches: gitCommitsAllLocalBranchesAfterDeploy,
Expand Down
1 change: 0 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export async function main() {
environment,
exec,
logger,
gitRootDirectory: git.getDirectory(),
userScriptCurrentWorkingDirectory: environment.getUserScriptCurrentWorkingDirectory(git.getDirectory()),
}),
prepareEnvironmentForTestMode: new PrepareTestModeEnvStepImpl(githubApi, environment, new SimulateMergeImpl(git, logger), git),
Expand Down
1 change: 1 addition & 0 deletions lib/exec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const givenPluginInput: DeployStepInput = {
gitCurrentBranch: "main",
gitRepoOwner: "owner",
gitRepoName: "repo",
gitRootDirectory: Deno.cwd(),
gitCommitsSinceLastRelease: [],
nextVersionName: "1.0.0",
testMode: true,
Expand Down
2 changes: 0 additions & 2 deletions lib/shebang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,10 @@ export async function runShebangCommand(
suppressCommandLogs: true, // the script is located in /tmp/ with a random string name so this would just look odd.
/**
* We must run the shebang script in the directory where the script is located so it can resolve any relative paths it needs to run.
* We then pass in the DECAF_ROOT_WORKING_DIRECTORY environment variable so the script can then change to the working directory where the codebase is located and run it's commands there.
*/
currentWorkingDirectory: tempDir,
envVars: {
...envVars,
DECAF_ROOT_WORKING_DIRECTORY: Deno.cwd(),
},
throwOnNonZeroExitCode: false,
})
Expand Down
50 changes: 17 additions & 33 deletions lib/step-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ Deno.test("given output is in stdout, expect return latest step", async () => {
environment,
exec,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const testInput: GetLatestReleaseStepInput = {
gitCurrentBranch: "main",
gitRepoOwner: "test",
gitRepoName: "test",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand All @@ -52,14 +52,14 @@ Deno.test("given output is in stdout as JSON, expect output is returned", async
environment,
exec: mockExec as unknown as ExecImpl,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const actual = await stepRunner.runGetLatestOnCurrentBranchReleaseStep({
gitCurrentBranch: "main",
gitRepoOwner: "owner",
gitRepoName: "repo",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsAllLocalBranches: {},
gitCommitsCurrentBranch: [],
Expand All @@ -75,14 +75,14 @@ Deno.test("given no command for step, expect return null", async () => {
environment,
exec,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const testInput: GetLatestReleaseStepInput = {
gitCurrentBranch: "main",
gitRepoOwner: "test",
gitRepoName: "test",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand All @@ -98,14 +98,14 @@ Deno.test("given output is not valid, expect null is returned", async () => {
environment,
exec,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const testInput: GetLatestReleaseStepInput = {
gitCurrentBranch: "main",
gitRepoOwner: "test",
gitRepoName: "test",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand All @@ -132,14 +132,14 @@ Deno.test("supports template engine in command string", async () => {
environment,
exec,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const actual = await stepRunner.runGetLatestOnCurrentBranchReleaseStep({
gitCurrentBranch: "main",
gitRepoOwner: "owner",
gitRepoName: "repo",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsAllLocalBranches: {
"branch-1": [
Expand Down Expand Up @@ -181,14 +181,14 @@ Deno.test("runGetLatestOnCurrentBranchReleaseStep - given return latest release
environment,
exec,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const testInput: GetLatestReleaseStepInput = {
gitCurrentBranch: "main",
gitRepoOwner: "test",
gitRepoName: "test",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand All @@ -210,14 +210,14 @@ Deno.test("determineNextReleaseVersionStep - given return next release as JSON,
environment,
exec,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const testInput: GetNextReleaseVersionStepInput = {
gitCurrentBranch: "main",
gitRepoOwner: "test",
gitRepoName: "test",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand All @@ -239,14 +239,14 @@ Deno.test("runDeployStep - given deploy command, expect to run successfully with
environment,
exec,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const deployInput: DeployStepInput = {
gitCurrentBranch: "main",
gitRepoOwner: "owner",
gitRepoName: "repo",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand Down Expand Up @@ -279,14 +279,14 @@ Deno.test("deploy step runs all commands in order", async () => {
environment,
exec: mockExec as unknown as ExecImpl,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const deployInput: DeployStepInput = {
gitCurrentBranch: "main",
gitRepoOwner: "owner",
gitRepoName: "repo",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand Down Expand Up @@ -329,14 +329,14 @@ Deno.test("non-deploy step runs all commands and does not exit early", async ()
environment,
exec: mockExec as unknown as ExecImpl,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const testInput: GetLatestReleaseStepInput = {
gitCurrentBranch: "main",
gitRepoOwner: "test",
gitRepoName: "test",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand Down Expand Up @@ -385,14 +385,14 @@ Deno.test("scripts cumulatively merge all outputs so each script builds on all p
environment,
exec: mockExec as unknown as ExecImpl,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const testInput: GetLatestReleaseStepInput = {
gitCurrentBranch: "main",
gitRepoOwner: "test",
gitRepoName: "test",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand Down Expand Up @@ -445,14 +445,14 @@ Deno.test("scripts cannot override original decaf input fields via output", asyn
environment,
exec: mockExec as unknown as ExecImpl,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const testInput: GetLatestReleaseStepInput = {
gitCurrentBranch: "main",
gitRepoOwner: "original-owner",
gitRepoName: "test",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand All @@ -478,14 +478,14 @@ Deno.test("non-deploy step returns null if all commands have invalid output", as
environment,
exec,
logger,
gitRootDirectory: Deno.cwd(),
userScriptCurrentWorkingDirectory: Deno.cwd(),
})

const testInput: GetLatestReleaseStepInput = {
gitCurrentBranch: "main",
gitRepoOwner: "test",
gitRepoName: "test",
gitRootDirectory: Deno.cwd(),
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand All @@ -501,8 +501,7 @@ Deno.test("non-deploy step returns null if all commands have invalid output", as
* Tests for working directory behavior.
*/

Deno.test("all step runner methods run commands from user script working directory and set DECAF_ROOT_WORKING_DIRECTORY env var", async () => {
const testGitRootDirectory = "/test/git/root"
Deno.test("all step runner methods run commands from user script working directory", async () => {
const testUserScriptWorkingDirectory = "/test/git/root/subdirectory"
const getLatestReleaseOutput: GetLatestReleaseStepOutput = { versionName: "1.0.0", commitSha: "abc" }
const getNextVersionOutput: GetNextReleaseVersionStepOutput = { version: "2.0.0" }
Expand Down Expand Up @@ -532,7 +531,6 @@ Deno.test("all step runner methods run commands from user script working directo
environment,
exec: mockExec as unknown as ExecImpl,
logger,
gitRootDirectory: testGitRootDirectory,
userScriptCurrentWorkingDirectory: testUserScriptWorkingDirectory,
})

Expand All @@ -541,6 +539,7 @@ Deno.test("all step runner methods run commands from user script working directo
gitCurrentBranch: "main",
gitRepoOwner: "test",
gitRepoName: "test",
gitRootDirectory: testUserScriptWorkingDirectory,
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand All @@ -550,6 +549,7 @@ Deno.test("all step runner methods run commands from user script working directo
gitCurrentBranch: "main",
gitRepoOwner: "test",
gitRepoName: "test",
gitRootDirectory: testUserScriptWorkingDirectory,
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand All @@ -561,6 +561,7 @@ Deno.test("all step runner methods run commands from user script working directo
gitCurrentBranch: "main",
gitRepoOwner: "owner",
gitRepoName: "repo",
gitRootDirectory: testUserScriptWorkingDirectory,
testMode: false,
gitCommitsCurrentBranch: [],
gitCommitsAllLocalBranches: {},
Expand All @@ -584,21 +585,4 @@ Deno.test("all step runner methods run commands from user script working directo
"determineNextReleaseVersionStep should run from user script working directory",
)
assertEquals(capturedCalls[2].workingDirectory, testUserScriptWorkingDirectory, "runDeployStep should run from user script working directory")

// Verify all three commands received DECAF_ROOT_WORKING_DIRECTORY env var with correct value
assertEquals(
capturedCalls[0].envVars?.DECAF_ROOT_WORKING_DIRECTORY,
testGitRootDirectory,
"runGetLatestOnCurrentBranchReleaseStep should pass DECAF_ROOT_WORKING_DIRECTORY env var",
)
assertEquals(
capturedCalls[1].envVars?.DECAF_ROOT_WORKING_DIRECTORY,
testGitRootDirectory,
"determineNextReleaseVersionStep should pass DECAF_ROOT_WORKING_DIRECTORY env var",
)
assertEquals(
capturedCalls[2].envVars?.DECAF_ROOT_WORKING_DIRECTORY,
testGitRootDirectory,
"runDeployStep should pass DECAF_ROOT_WORKING_DIRECTORY env var",
)
})
Loading