diff --git a/.github/actions/use-local-dockerfile/action.yml b/.github/actions/use-local-dockerfile/action.yml index cfb62f4..74b1af6 100644 --- a/.github/actions/use-local-dockerfile/action.yml +++ b/.github/actions/use-local-dockerfile/action.yml @@ -1,12 +1,16 @@ name: "Use local Dockerfile" description: "Use the local Dockerfile to test the action instead of the one on DockerHub" - +inputs: + working_directory: + description: 'Directory to manipulate Dockerfile in' + required: true + default: '.' runs: using: "composite" steps: - name: Replace image on action.yml shell: bash run: | - mv action.yml previous.yml - sed "s|docker://ghcr.io/getsentry/action-release-image:latest|Dockerfile|" previous.yml >> action.yml - grep "image" action.yml + mv ${{inputs.working_directory}}/action.yml ${{inputs.working_directory}}/previous.yml + sed "s|docker://ghcr.io/getsentry/action-release-image:latest|Dockerfile|" ${{inputs.working_directory}}/previous.yml >> ${{inputs.working_directory}}/action.yml + grep "image" ${{inputs.working_directory}}/action.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e00c2de..2e6c221 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,4 +21,30 @@ jobs: env: MOCK: true with: - environment: production \ No newline at end of file + environment: production + + mock-release-working-directory: + name: "Build image & mock a release in a different working directory" + runs-on: ubuntu-latest + steps: + - name: Checkout directory we'll be running from + uses: actions/checkout@v3 + with: + path: main/ + + - name: Checkout directory we'll be testing + uses: actions/checkout@v3 + with: + path: test/ + + - uses: './main/.github/actions/use-local-dockerfile' + with: + working_directory: main + + - name: Mock creating a Sentry release in a different directory + uses: ./main + env: + MOCK: true + with: + environment: production + working_directory: ./test diff --git a/README.md b/README.md index c1cc3f3..77fbee6 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ Adding the following to your workflow will create a new Sentry release and tell |`projects`|Space-separated list of paths of projects. When omitted, falls back to the environment variable `SENTRY_PROJECT` to determine the project.|-| |`url_prefix`|Adds a prefix to source map urls after stripping them.|-| |`strip_common_prefix`|Will remove a common prefix from uploaded filenames. Useful for removing a path that is build-machine-specific.|`false`| +|`working_directory`|Directory to collect sentry release information from. Useful when collecting information from a non-standard checkout directory.|-| ### Examples diff --git a/action.yml b/action.yml index 7bb4a33..72fd500 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,9 @@ inputs: strip_common_prefix: description: 'Will remove a common prefix from uploaded filenames. Useful for removing a path that is build-machine-specific.' required: false + working_directory: + description: 'Directory to collect sentry release information from. Useful when collecting information from a non-standard checkout directory.' + required: false runs: using: 'docker' # If you change this, update the use-local-dockerfile action diff --git a/src/main.ts b/src/main.ts index 55a1ff5..b4a9439 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core'; import {getCLI} from './cli'; import * as options from './options'; +import * as process from 'process'; (async () => { try { @@ -23,10 +24,16 @@ import * as options from './options'; false ); const version = await options.getVersion(); + const workingDirectory = options.getWorkingDirectory(); core.debug(`Version is ${version}`); await cli.new(version, {projects}); + const currentWorkingDirectory = process.cwd(); + if (workingDirectory !== null && workingDirectory.length > 0) { + process.chdir(workingDirectory); + } + if (setCommitsOption !== 'skip') { core.debug(`Setting commits with option '${setCommitsOption}'`); await cli.setCommits(version, { @@ -66,6 +73,10 @@ import * as options from './options'; await cli.finalize(version); } + if (workingDirectory !== null && workingDirectory.length > 0) { + process.chdir(currentWorkingDirectory); + } + core.debug(`Done`); core.setOutput('version', version); } catch (error) { diff --git a/src/options.ts b/src/options.ts index fd6ffec..80e62ab 100644 --- a/src/options.ts +++ b/src/options.ts @@ -165,3 +165,7 @@ export const getProjects = (): string[] => { export const getUrlPrefixOption = (): string => { return core.getInput('url_prefix'); }; + +export const getWorkingDirectory = (): string => { + return core.getInput('working_directory'); +};