From d53da5fecec66f52f3469d9f2b899aa0c539cce8 Mon Sep 17 00:00:00 2001 From: Leander Rodrigues Date: Wed, 22 Jun 2022 17:29:12 -0700 Subject: [PATCH] fix(ci): Repair CI for OS contributors (#91) This PR fixes the CI workflow to generate values for environment variables if the MOCK env var is set. Previously the values needed to be set on the repository which works as well, but exists outside the code and elevated permissions to just run CI (meaning OS contributions would fail CI). This behaviour is fine since it doesn't actually use these variables as network requests are stubbed when MOCK is set. This was achieved by using the current repo for generating an image, rather than the published version. If the local image passes all tests and has been reviewed, it makes sense for it to be published afterward. Testing changes in this repo against the published version prevents testing new behaviour. --- .github/actions/setup-docker/action.yml | 13 +++++++++++++ .github/workflows/test.yml | 12 +++++------- CONTRIBUTING | 2 +- src/cli.ts | 8 ++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 .github/actions/setup-docker/action.yml diff --git a/.github/actions/setup-docker/action.yml b/.github/actions/setup-docker/action.yml new file mode 100644 index 0000000..c4e1f7d --- /dev/null +++ b/.github/actions/setup-docker/action.yml @@ -0,0 +1,13 @@ +name: "Setup Docker" +description: "Use the local Dockerfile to test the action instead of the one on DockerHub" + +runs: + using: "composite" + steps: + - name: Replace image on action.yml + shell: bash + env: + ESC_DOCKER_IMAGE_LINK: 'docker\:\/\/sentryintegrations\/sentry-github-action-release\:latest' + run: | + mv action.yml previous.yml + sed "s/$ESC_DOCKER_IMAGE_LINK/Dockerfile/" previous.yml >> action.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 911a11a..be69a24 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,5 @@ name: "test" -on: # rebuild any PRs and main branch changes +on: pull_request: push: branches: @@ -7,16 +7,14 @@ on: # rebuild any PRs and main branch changes - 'releases/*' jobs: - test: # make sure the action works on a clean machine without building + mock: # Make sure that the action works on a clean machine without building runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Create Sentry release + - uses: actions/checkout@v3 + - uses: './.github/actions/setup-docker' + - name: Mock creating a Sentry release uses: ./ env: - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - SENTRY_ORG: ${{ secrets.SENTRY_ORG }} - SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} MOCK: true with: environment: production diff --git a/CONTRIBUTING b/CONTRIBUTING index ca4c742..c85e6fa 100644 --- a/CONTRIBUTING +++ b/CONTRIBUTING @@ -1,4 +1,4 @@ # Contributing Feel free to use GitHub's pull request features to propose changes. -See the [Code of Conduct](https://github.com/getsentry/.github/blob/master/CODE_OF_CONDUCT.md). +See the [Code of Conduct](https://github.com/getsentry/.github/blob/main/CODE_OF_CONDUCT.md). diff --git a/src/cli.ts b/src/cli.ts index e3831ae..2a8aa1a 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -15,6 +15,14 @@ export const getCLI = (): SentryCliReleases => { if (!cli) { cli = new SentryCli().releases; if (process.env['MOCK']) { + // Set environment variables if they aren't already + for (const variable of [ + 'SENTRY_AUTH_TOKEN', + 'SENTRY_ORG', + 'SENTRY_PROJECT', + ]) + !(variable in process.env) && (process.env[variable] = variable); + cli.execute = async ( args: string[], // eslint-disable-next-line @typescript-eslint/no-unused-vars