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: implement 'working-directory' argument #120

Merged
merged 8 commits into from
Feb 22, 2023
Merged
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: 8 additions & 4 deletions .github/actions/use-local-dockerfile/action.yml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 27 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,30 @@ jobs:
env:
MOCK: true
with:
environment: production
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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, {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};