From b39c133c853fbcbe1d39be1ae4246427dbb5dfbc Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 10:15:42 +0100 Subject: [PATCH 01/29] feat: Use hybrid approach depending on runner --- .dockerignore | 10 ++++++ .github/workflows/build.yml | 61 ++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 2 +- Dockerfile | 32 +++++++++++++++++ action.yml | 37 ++++++++++++++++--- entrypoint.sh | 2 ++ package.json | 4 +-- scripts/craft-pre-release.sh | 3 ++ scripts/set-branch-docker-tag.sh | 9 +++++ scripts/set-docker-tag.sh | 13 +++++++ 10 files changed, 166 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/build.yml create mode 100644 Dockerfile create mode 100644 entrypoint.sh create mode 100755 scripts/set-branch-docker-tag.sh create mode 100755 scripts/set-docker-tag.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..ed2dfea9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +# Docs: https://docs.docker.com/engine/reference/builder/#dockerignore-file +# These files will be ignore by Docker for COPY and ADD commands when creating a build context +# In other words, if a file should not be inside of the Docker container it should be +# added to the list, otherwise, it will invalidate cache layers and have to rebuild +# all layers after a COPY command +.git +.github +Dockerfile +.dockerignore +*.md \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..abfabc91 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,61 @@ +name: "build" +on: + pull_request: + types: + - opened + - synchronize + - reopened + +jobs: + docker-build: + name: Build & publish Docker images + runs-on: ubuntu-latest + permissions: + packages: write + strategy: + matrix: + target: + - name: builder + image: action-release-builder-image + - name: app + image: action-release-image + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Extract docker tag + run: | + TAG=$(yq '... | select(has("uses") and .uses | test("docker://ghcr.io/getsentry/action-release-image:.*")) | .uses' action.yml | awk -F':' '{print $3}') + echo "DOCKER_TAG=$TAG" >> $GITHUB_ENV + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # BUILDKIT_INLINE_CACHE creates the image in such a way that you can + # then use --cache-from (think of a remote cache) + # This feature is allowed thanks to using the buildx plugin + # + # There's a COPY command in the builder stage that can easily invalidate the cache + # If you notice, please add more exceptions to .dockerignore since we loose the value + # of using --cache-from on the app stage + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.target.image }}:${{ env.DOCKER_TAG }} + cache-from: ghcr.io/${{ github.repository_owner }}/${{ matrix.target.image }}:master + target: ${{ matrix.target.name }} + build-args: BUILDKIT_INLINE_CACHE=1 \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 29245651..0868f2f8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Prepare Release +name: "Action: Prepare Release" on: workflow_dispatch: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a7647123 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# The multi stage set up *saves* up image size by avoiding the dev dependencies +# required to produce dist/ +FROM node:18-alpine as builder +WORKDIR /app +# This layer will invalidate upon new dependencies +COPY package.json yarn.lock ./ +RUN export YARN_CACHE_FOLDER="$(mktemp -d)" \ + && yarn install --frozen-lockfile --quiet \ + && rm -r "$YARN_CACHE_FOLDER" +# If there's some code changes that causes this layer to +# invalidate but it shouldn't, use .dockerignore to exclude it +COPY . . +RUN yarn build + +FROM node:18-alpine as app +COPY package.json yarn.lock /action-release/ +# On the builder image, we install both types of dependencies rather than +# just the production ones. This generates /action-release/node_modules +RUN export YARN_CACHE_FOLDER="$(mktemp -d)" \ + && cd /action-release \ + && yarn install --frozen-lockfile --production --quiet \ + && rm -r "$YARN_CACHE_FOLDER" + +# Copy the artifacts from `yarn build` +COPY --from=builder /app/dist /action-release/dist/ +RUN chmod +x /action-release/dist/index.js + +RUN printf '[safe]\n directory = *\n' > /etc/gitconfig + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/action.yml b/action.yml index 26331d48..f000f251 100644 --- a/action.yml +++ b/action.yml @@ -58,20 +58,47 @@ inputs: runs: using: 'composite' steps: +# - name: Extract tag to use for docker image +# if: runner.os == 'Linux' +# shell: bash +# run: | +# GIT_REF="${{ github.action_ref }}" +# if [[ "$GIT_REF" == refs/tags/* ]]; then +# DOCKER_TAG=${REF#refs/tags/} +# elif [[ "$GIT_REF" == refs/heads/* ]]; then +# DOCKER_TAG=${GIT_REF#refs/heads/} +# else +# DOCKER_TAG="master" +# fi +# echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV + + # For actions running on a linux runner, we use a docker + # approach as it's faster and encapsulates everything needed + # to run the action. + - name: Run docker image + if: runner.os != 'macOS' && runner.os != 'Windows' + uses: docker://ghcr.io/getsentry/action-release-image:ab/multiarch-docker + + # For actions running on macos or windows runners, we use a composite + # action approach so it allows us to install the arch specific sentry-cli + # that's needed for the runner. This is slower and runners require to have + # node and npm available. - name: Mark GitHub workspace a safe directory in git - if: ${{ inputs.disable_safe_directory != 'true' }} + if: ${{ (runner.os == 'macOS' || runner.os == 'Windows') && inputs.disable_safe_directory != 'true' }} shell: bash run: | git config --global --add safe.directory "$GITHUB_WORKSPACE" - - name: Get node version + - name: Get node and npm versions + if: runner.os == 'macOS' || runner.os == 'Windows' shell: bash run: | echo "NODE_VERSION=$(node -v 2>/dev/null || echo '')" >> $GITHUB_ENV + echo "NPM_VERSION=$(npm -v 2>/dev/null || echo '')" >> $GITHUB_ENV - name: Setup node # Only install node if there isn't one already - if: env.NODE_VERSION == '' + if: ${{ (runner.os == 'macOS' || runner.os == 'Windows') && (env.NODE_VERSION == '' || env.NPM_VERSION == '') }} uses: actions/setup-node@v4 with: # setup-node doesn't allow absolute paths, so we can't @@ -80,11 +107,13 @@ runs: node-version: 18.17.0 - name: Install Sentry CLI v2 + if: runner.os == 'macOS' || runner.os == 'Windows' shell: bash - run: npm install --save-dev --no-package-lock @sentry/cli@^2.4 + run: npm install --no-package-lock @sentry/cli@^2.4 working-directory: ${{ github.action_path }} - name: Run Release Action + if: runner.os == 'macOS' || runner.os == 'Windows' env: # Composite actions don't pass the outer action's inputs # down into these steps, so we have to replicate all inputs to be accessible diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 00000000..14517000 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,2 @@ +#!/bin/sh -l +node /action-release/dist/index.js \ No newline at end of file diff --git a/package.json b/package.json index 1ef25cbe..dc3cd825 100644 --- a/package.json +++ b/package.json @@ -26,10 +26,10 @@ "license": "MIT", "dependencies": { "@actions/core": "^1.11.1", - "@sentry/node": "^8.54.0" + "@sentry/node": "^8.54.0", + "@sentry/cli": "^2.41.1" }, "devDependencies": { - "@sentry/cli": "^2.41.1", "@types/jest": "^29.5.6", "@types/node": "^20.8.9", "@typescript-eslint/parser": "^6.9.0", diff --git a/scripts/craft-pre-release.sh b/scripts/craft-pre-release.sh index d5ee22b3..a42ca476 100644 --- a/scripts/craft-pre-release.sh +++ b/scripts/craft-pre-release.sh @@ -16,3 +16,6 @@ npm version "${NEW_VERSION}" # The build output contains the package.json so we need to # rebuild to ensure it's reflected after bumping the version yarn install && yarn build + +# Update the docker tag in action.yml +./scripts/set-docker-tag $NEW_VERSION diff --git a/scripts/set-branch-docker-tag.sh b/scripts/set-branch-docker-tag.sh new file mode 100755 index 00000000..e459ae33 --- /dev/null +++ b/scripts/set-branch-docker-tag.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -eux + +BRANCH=$(git rev-parse --abbrev-ref HEAD) + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $SCRIPT_DIR + +./set-docker-tag.sh $BRANCH diff --git a/scripts/set-docker-tag.sh b/scripts/set-docker-tag.sh new file mode 100755 index 00000000..86ebe7a0 --- /dev/null +++ b/scripts/set-docker-tag.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -eux + +DOCKER_REGISTRY_IMAGE="docker://ghcr.io/getsentry/action-release-image" +TAG="${1}" + +# Move to the project root +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $SCRIPT_DIR/.. + +# We don't want the backup but this is the only way to make this +# work on macos as well +sed -i.bak -e "s|\($DOCKER_REGISTRY_IMAGE:\)[^']*|\1$TAG|" action.yml && rm -f action.yml.bak From facec1c0726c25e20ed2e3aa5fc97e2d857c1cd9 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 10:18:14 +0100 Subject: [PATCH 02/29] Fix tag --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f000f251..356b6061 100644 --- a/action.yml +++ b/action.yml @@ -77,7 +77,7 @@ runs: # to run the action. - name: Run docker image if: runner.os != 'macOS' && runner.os != 'Windows' - uses: docker://ghcr.io/getsentry/action-release-image:ab/multiarch-docker + uses: docker://ghcr.io/getsentry/action-release-image:ab-multiarch-docker # For actions running on macos or windows runners, we use a composite # action approach so it allows us to install the arch specific sentry-cli From 1cb0224e5899839c33c90521136a41507bcdaab6 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 10:31:34 +0100 Subject: [PATCH 03/29] Update dist --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index daf1425a..2b11a248 100644 --- a/dist/index.js +++ b/dist/index.js @@ -123585,7 +123585,7 @@ module.exports = JSON.parse('{"eN":{"H":"https://github.com/elastic/require-in-t /***/ ((module) => { "use strict"; -module.exports = JSON.parse('{"name":"action-release","version":"1.10.5","private":true,"description":"GitHub Action for creating a release on Sentry","main":"dist/index.js","scripts":{"start":"node dist/index.js","build":"ncc build src/main.ts -e @sentry/cli","format":"prettier --write **/*.ts **/*.md","format-check":"prettier --check **/*.ts **/*.md","lint":"eslint src/**/*.ts","test":"jest","all":"yarn run format && yarn run lint && yarn run build && yarn test"},"repository":{"type":"git","url":"git+https://github.com/getsentry/action-release.git"},"keywords":["actions","sentry","release"],"author":"Sentry","license":"MIT","dependencies":{"@actions/core":"^1.11.1","@sentry/node":"^8.54.0"},"devDependencies":{"@sentry/cli":"^2.41.1","@types/jest":"^29.5.6","@types/node":"^20.8.9","@typescript-eslint/parser":"^6.9.0","@vercel/ncc":"^0.38.1","eslint":"^8.52.0","eslint-plugin-github":"^4.10.1","eslint-plugin-jest":"^27.4.3","jest":"^29.7.0","jest-circus":"^29.7.0","js-yaml":"^4.1.0","prettier":"^3.0.3","ts-jest":"^29.1.1","typescript":"^5.2.2"},"volta":{"node":"18.17.0","yarn":"1.22.4"}}'); +module.exports = JSON.parse('{"name":"action-release","version":"1.10.5","private":true,"description":"GitHub Action for creating a release on Sentry","main":"dist/index.js","scripts":{"start":"node dist/index.js","build":"ncc build src/main.ts -e @sentry/cli","format":"prettier --write **/*.ts **/*.md","format-check":"prettier --check **/*.ts **/*.md","lint":"eslint src/**/*.ts","test":"jest","all":"yarn run format && yarn run lint && yarn run build && yarn test"},"repository":{"type":"git","url":"git+https://github.com/getsentry/action-release.git"},"keywords":["actions","sentry","release"],"author":"Sentry","license":"MIT","dependencies":{"@actions/core":"^1.11.1","@sentry/node":"^8.54.0","@sentry/cli":"^2.41.1"},"devDependencies":{"@types/jest":"^29.5.6","@types/node":"^20.8.9","@typescript-eslint/parser":"^6.9.0","@vercel/ncc":"^0.38.1","eslint":"^8.52.0","eslint-plugin-github":"^4.10.1","eslint-plugin-jest":"^27.4.3","jest":"^29.7.0","jest-circus":"^29.7.0","js-yaml":"^4.1.0","prettier":"^3.0.3","ts-jest":"^29.1.1","typescript":"^5.2.2"},"volta":{"node":"18.17.0","yarn":"1.22.4"}}'); /***/ }) From bb834c5162ded886fc50a5a64fb6d10e61dbd52b Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 10:32:46 +0100 Subject: [PATCH 04/29] Add fetch depth to test --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 57d81c44..970805c1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,6 +52,8 @@ jobs: name: Test current action steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Create a staging release uses: ./ @@ -87,6 +89,7 @@ jobs: name: Mock a release steps: - uses: actions/checkout@v4 + fetch-depth: 0 - name: Mock creating a Sentry release uses: ./ @@ -105,11 +108,13 @@ jobs: - name: Checkout directory we'll be running from uses: actions/checkout@v4 with: + fetch-depth: 0 path: main/ - name: Checkout directory we'll be testing uses: actions/checkout@v4 with: + fetch-depth: 0 path: test/ - name: Mock creating a Sentry release in a different directory From 7102667b309162ef0187b018fd2385a98f7315ae Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 10:51:18 +0100 Subject: [PATCH 05/29] Add dependcy on docker-build job for test action --- .github/workflows/build.yml | 2 +- .github/workflows/test.yml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index abfabc91..f661e80c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,7 +25,7 @@ jobs: with: fetch-depth: 0 - - name: Extract docker tag + - name: Extract docker tag from action.yml run: | TAG=$(yq '... | select(has("uses") and .uses | test("docker://ghcr.io/getsentry/action-release-image:.*")) | .uses' action.yml | awk -F':' '{print $3}') echo "DOCKER_TAG=$TAG" >> $GITHUB_ENV diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 970805c1..1cef9db3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,6 +45,7 @@ jobs: # Secrets on this repo do not get shared with PRs opened on a fork, thus, # add SENTRY_AUTH_TOKEN as a secret to your fork if you want to use this job. create-staging-release-per-push: + needs: docker-build strategy: matrix: os: [ ubuntu-latest, windows-latest, macos-latest ] @@ -64,6 +65,7 @@ jobs: ignore_missing: true runs-on-container: + needs: docker-build runs-on: ubuntu-latest container: image: node:18.17 @@ -82,6 +84,7 @@ jobs: ignore_missing: true mock-release: + needs: docker-build strategy: matrix: os: [ ubuntu-latest, windows-latest, macos-latest ] @@ -99,6 +102,7 @@ jobs: environment: production mock-release-working-directory: + needs: docker-build strategy: matrix: os: [ ubuntu-latest, windows-latest, macos-latest ] From 583575147f4032aa34bcdad994b66c571f2bd571 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 11:22:26 +0100 Subject: [PATCH 06/29] Improve branch extraction naming, add npm scripts to bump docker tags --- action.yml | 14 -------------- dist/index.js | 2 +- package.json | 4 +++- scripts/craft-pre-release.sh | 2 +- scripts/set-branch-docker-tag.sh | 3 ++- 5 files changed, 7 insertions(+), 18 deletions(-) mode change 100644 => 100755 scripts/craft-pre-release.sh diff --git a/action.yml b/action.yml index 356b6061..5fb04894 100644 --- a/action.yml +++ b/action.yml @@ -58,20 +58,6 @@ inputs: runs: using: 'composite' steps: -# - name: Extract tag to use for docker image -# if: runner.os == 'Linux' -# shell: bash -# run: | -# GIT_REF="${{ github.action_ref }}" -# if [[ "$GIT_REF" == refs/tags/* ]]; then -# DOCKER_TAG=${REF#refs/tags/} -# elif [[ "$GIT_REF" == refs/heads/* ]]; then -# DOCKER_TAG=${GIT_REF#refs/heads/} -# else -# DOCKER_TAG="master" -# fi -# echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV - # For actions running on a linux runner, we use a docker # approach as it's faster and encapsulates everything needed # to run the action. diff --git a/dist/index.js b/dist/index.js index 2b11a248..8b46164f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -123585,7 +123585,7 @@ module.exports = JSON.parse('{"eN":{"H":"https://github.com/elastic/require-in-t /***/ ((module) => { "use strict"; -module.exports = JSON.parse('{"name":"action-release","version":"1.10.5","private":true,"description":"GitHub Action for creating a release on Sentry","main":"dist/index.js","scripts":{"start":"node dist/index.js","build":"ncc build src/main.ts -e @sentry/cli","format":"prettier --write **/*.ts **/*.md","format-check":"prettier --check **/*.ts **/*.md","lint":"eslint src/**/*.ts","test":"jest","all":"yarn run format && yarn run lint && yarn run build && yarn test"},"repository":{"type":"git","url":"git+https://github.com/getsentry/action-release.git"},"keywords":["actions","sentry","release"],"author":"Sentry","license":"MIT","dependencies":{"@actions/core":"^1.11.1","@sentry/node":"^8.54.0","@sentry/cli":"^2.41.1"},"devDependencies":{"@types/jest":"^29.5.6","@types/node":"^20.8.9","@typescript-eslint/parser":"^6.9.0","@vercel/ncc":"^0.38.1","eslint":"^8.52.0","eslint-plugin-github":"^4.10.1","eslint-plugin-jest":"^27.4.3","jest":"^29.7.0","jest-circus":"^29.7.0","js-yaml":"^4.1.0","prettier":"^3.0.3","ts-jest":"^29.1.1","typescript":"^5.2.2"},"volta":{"node":"18.17.0","yarn":"1.22.4"}}'); +module.exports = JSON.parse('{"name":"action-release","version":"1.10.5","private":true,"description":"GitHub Action for creating a release on Sentry","main":"dist/index.js","scripts":{"start":"node dist/index.js","build":"ncc build src/main.ts -e @sentry/cli","format":"prettier --write **/*.ts **/*.md","format-check":"prettier --check **/*.ts **/*.md","lint":"eslint src/**/*.ts","test":"jest","all":"yarn run format && yarn run lint && yarn run build && yarn test","bump-docker-tag":"./scripts/set-docker-tag.sh","bump-docker-tag-from-branch":"./scripts/set-branch-docker-tag.sh"},"repository":{"type":"git","url":"git+https://github.com/getsentry/action-release.git"},"keywords":["actions","sentry","release"],"author":"Sentry","license":"MIT","dependencies":{"@actions/core":"^1.11.1","@sentry/node":"^8.54.0","@sentry/cli":"^2.41.1"},"devDependencies":{"@types/jest":"^29.5.6","@types/node":"^20.8.9","@typescript-eslint/parser":"^6.9.0","@vercel/ncc":"^0.38.1","eslint":"^8.52.0","eslint-plugin-github":"^4.10.1","eslint-plugin-jest":"^27.4.3","jest":"^29.7.0","jest-circus":"^29.7.0","js-yaml":"^4.1.0","prettier":"^3.0.3","ts-jest":"^29.1.1","typescript":"^5.2.2"},"volta":{"node":"18.17.0","yarn":"1.22.4"}}'); /***/ }) diff --git a/package.json b/package.json index dc3cd825..ccc45b6e 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,9 @@ "format-check": "prettier --check **/*.ts **/*.md", "lint": "eslint src/**/*.ts", "test": "jest", - "all": "yarn run format && yarn run lint && yarn run build && yarn test" + "all": "yarn run format && yarn run lint && yarn run build && yarn test", + "bump-docker-tag": "./scripts/set-docker-tag.sh", + "bump-docker-tag-from-branch": "./scripts/set-branch-docker-tag.sh" }, "repository": { "type": "git", diff --git a/scripts/craft-pre-release.sh b/scripts/craft-pre-release.sh old mode 100644 new mode 100755 index a42ca476..54c72560 --- a/scripts/craft-pre-release.sh +++ b/scripts/craft-pre-release.sh @@ -18,4 +18,4 @@ npm version "${NEW_VERSION}" yarn install && yarn build # Update the docker tag in action.yml -./scripts/set-docker-tag $NEW_VERSION +yarn bump-docker-tag "${NEW_VERSION}" diff --git a/scripts/set-branch-docker-tag.sh b/scripts/set-branch-docker-tag.sh index e459ae33..f626b04d 100755 --- a/scripts/set-branch-docker-tag.sh +++ b/scripts/set-branch-docker-tag.sh @@ -1,7 +1,8 @@ #!/bin/bash set -eux -BRANCH=$(git rev-parse --abbrev-ref HEAD) +# Extract the branch name from git and replace all non-alphanumerical characters with `-` +BRANCH=$(git rev-parse --abbrev-ref HEAD | sed 's/[^a-zA-Z0-9-]/-/g') SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $SCRIPT_DIR From 35164c10ba58989ec4136be1ab70cd3e94980048 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 11:37:22 +0100 Subject: [PATCH 07/29] Pass inputs along --- action.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/action.yml b/action.yml index 5fb04894..c0bb4870 100644 --- a/action.yml +++ b/action.yml @@ -63,6 +63,27 @@ runs: # to run the action. - name: Run docker image if: runner.os != 'macOS' && runner.os != 'Windows' + env: + # Composite actions don't pass the outer action's inputs + # down into these steps, so we have to replicate all inputs to be accessible + # via @actions/core + INPUT_ENVIRONMENT: ${{ inputs.environment }} + INPUT_INJECT: ${{ inputs.inject }} + INPUT_SOURCEMAPS: ${{ inputs.sourcemaps }} + INPUT_DIST: ${{ inputs.dist }} + INPUT_FINALIZE: ${{ inputs.finalize }} + INPUT_IGNORE_MISSING: ${{ inputs.ignore_missing }} + INPUT_IGNORE_EMPTY: ${{ inputs.ignore_empty }} + INPUT_STARTED_AT: ${{ inputs.started_at }} + INPUT_VERSION: ${{ inputs.version }} + INPUT_VERSION_PREFIX: ${{ inputs.version_prefix }} + INPUT_SET_COMMITS: ${{ inputs.set_commits }} + INPUT_PROJECTS: ${{ inputs.projects }} + INPUT_URL_PREFIX: ${{ inputs.url_prefix }} + INPUT_STRIP_COMMON_PREFIX: ${{ inputs.strip_common_prefix }} + INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }} + INPUT_DISABLE_TELEMETRY: ${{ inputs.disable_telemetry }} + INPUT_DISABLE_SAFE_DIRECTORY: ${{ inputs.disable_safe_directory }} uses: docker://ghcr.io/getsentry/action-release-image:ab-multiarch-docker # For actions running on macos or windows runners, we use a composite From a34995c0091808c8d5aed039282db1d92527cdcb Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 11:47:29 +0100 Subject: [PATCH 08/29] Run tests on workflow_run completed --- .github/workflows/test.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1cef9db3..ecce992f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,15 +1,10 @@ name: Integration Tests on: - pull_request: - paths-ignore: - - "**.md" - push: - branches: - - master - - release/** - paths-ignore: - - "**.md" + workflow_run: + workflows: [ build ] + types: + - completed env: # Variables defined in the repository @@ -45,7 +40,6 @@ jobs: # Secrets on this repo do not get shared with PRs opened on a fork, thus, # add SENTRY_AUTH_TOKEN as a secret to your fork if you want to use this job. create-staging-release-per-push: - needs: docker-build strategy: matrix: os: [ ubuntu-latest, windows-latest, macos-latest ] @@ -65,7 +59,6 @@ jobs: ignore_missing: true runs-on-container: - needs: docker-build runs-on: ubuntu-latest container: image: node:18.17 @@ -84,7 +77,6 @@ jobs: ignore_missing: true mock-release: - needs: docker-build strategy: matrix: os: [ ubuntu-latest, windows-latest, macos-latest ] @@ -102,7 +94,6 @@ jobs: environment: production mock-release-working-directory: - needs: docker-build strategy: matrix: os: [ ubuntu-latest, windows-latest, macos-latest ] From 4a0624ec2845fb67f60aab1b1f8a38fc6b7ca657 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 11:56:34 +0100 Subject: [PATCH 09/29] Update workflow run trigger --- .github/workflows/build.yml | 3 ++- .github/workflows/test.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f661e80c..94e8ad6b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,5 @@ -name: "build" +name: "Build docker" + on: pull_request: types: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ecce992f..690f6787 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,8 @@ name: Integration Tests on: workflow_run: - workflows: [ build ] + workflows: + - "Build docker" types: - completed From 84831cef16ec1d7323744bfdc6a6bd0a53d9cfe7 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 12:00:23 +0100 Subject: [PATCH 10/29] Fix fetch-depth --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 690f6787..5330e99d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -85,7 +85,8 @@ jobs: name: Mock a release steps: - uses: actions/checkout@v4 - fetch-depth: 0 + with: + fetch-depth: 0 - name: Mock creating a Sentry release uses: ./ From f820432574473241f57a25c7e1cdebcff664dd27 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 13:08:03 +0100 Subject: [PATCH 11/29] Update comment --- action.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index c0bb4870..67819621 100644 --- a/action.yml +++ b/action.yml @@ -87,9 +87,8 @@ runs: uses: docker://ghcr.io/getsentry/action-release-image:ab-multiarch-docker # For actions running on macos or windows runners, we use a composite - # action approach so it allows us to install the arch specific sentry-cli - # that's needed for the runner. This is slower and runners require to have - # node and npm available. + # action approach which allows us to install the arch specific sentry-cli + # binary that's needed for the runner. This is slower. - name: Mark GitHub workspace a safe directory in git if: ${{ (runner.os == 'macOS' || runner.os == 'Windows') && inputs.disable_safe_directory != 'true' }} shell: bash From d3bbc8efae67bad71448fc6b2ccefed61d7b2448 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 13:09:41 +0100 Subject: [PATCH 12/29] Update workflow naming --- .github/workflows/build.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 94e8ad6b..40791265 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: "Build docker" +name: "Build Docker Image" on: pull_request: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5330e99d..e1fb749a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: Integration Tests on: workflow_run: workflows: - - "Build docker" + - "Build Docker Image" types: - completed From 4b55e4c327eb05a430b494604f5b6491992ed932 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 13:22:17 +0100 Subject: [PATCH 13/29] Update workflow names --- .github/workflows/build.yml | 2 +- .github/workflows/test.yml | 3 +-- action.yml | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 40791265..b04e92ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: "Build Docker Image" +name: Build Docker Image on: pull_request: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e1fb749a..8d217e85 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,8 +2,7 @@ name: Integration Tests on: workflow_run: - workflows: - - "Build Docker Image" + workflows: [Build Docker Image] types: - completed diff --git a/action.yml b/action.yml index 67819621..e1163a3e 100644 --- a/action.yml +++ b/action.yml @@ -66,7 +66,7 @@ runs: env: # Composite actions don't pass the outer action's inputs # down into these steps, so we have to replicate all inputs to be accessible - # via @actions/core + # via @actions/core here and in the `Run Release Action` step further down. INPUT_ENVIRONMENT: ${{ inputs.environment }} INPUT_INJECT: ${{ inputs.inject }} INPUT_SOURCEMAPS: ${{ inputs.sourcemaps }} From 6c5c926f10459624b085f0a5d3a0aa2c877150c0 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 13:34:33 +0100 Subject: [PATCH 14/29] Merge test.yml into build.yml to run tests after building --- .github/workflows/build.yml | 123 +++++++++++++++++++++++++++++++++++- .github/workflows/test.yml | 122 ----------------------------------- docs/development.md | 2 +- 3 files changed, 122 insertions(+), 125 deletions(-) delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b04e92ee..509a91d1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build Docker Image +name: Build and Test on: pull_request: @@ -7,6 +7,15 @@ on: - synchronize - reopened +env: + # Variables defined in the repository + SENTRY_ORG: ${{ vars.SENTRY_ORG }} + # For master, we have an environment variable that selects the action-release project + # instead of action-release-prs + # For other branches: https://sentry-ecosystem.sentry.io/releases/?project=4505075304693760 + # For master branch: https://sentry-ecosystem.sentry.io/releases/?project=6576594 + SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }} + jobs: docker-build: name: Build & publish Docker images @@ -59,4 +68,114 @@ jobs: tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.target.image }}:${{ env.DOCKER_TAG }} cache-from: ghcr.io/${{ github.repository_owner }}/${{ matrix.target.image }}:master target: ${{ matrix.target.name }} - build-args: BUILDKIT_INLINE_CACHE=1 \ No newline at end of file + build-args: BUILDKIT_INLINE_CACHE=1 + + lint: + needs: docker-build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install + run: yarn install + + - name: Check format + run: yarn format-check + + - name: Lint + run: yarn lint + + - name: Build + run: yarn build + + # You're welcome to make changes on this job as part of your PR in order to test out your changes + # We can always undo the changes once we're satisfied with the results + # + # Secrets on this repo do not get shared with PRs opened on a fork, thus, + # add SENTRY_AUTH_TOKEN as a secret to your fork if you want to use this job. + create-staging-release-per-push: + needs: docker-build + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + runs-on: ${{ matrix.os }} + name: Test current action + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Create a staging release + uses: ./ + env: + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + SENTRY_LOG_LEVEL: debug + with: + ignore_missing: true + + runs-on-container: + needs: docker-build + runs-on: ubuntu-latest + container: + image: node:18.17 + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Create a staging release + uses: ./ + env: + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + SENTRY_LOG_LEVEL: debug + with: + ignore_missing: true + + mock-release: + needs: docker-build + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + runs-on: ${{ matrix.os }} + name: Mock a release + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Mock creating a Sentry release + uses: ./ + env: + MOCK: true + with: + environment: production + + mock-release-working-directory: + needs: docker-build + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + runs-on: ${{ matrix.os }} + name: Mock a release in a different working directory + steps: + - name: Checkout directory we'll be running from + uses: actions/checkout@v4 + with: + fetch-depth: 0 + path: main/ + + - name: Checkout directory we'll be testing + uses: actions/checkout@v4 + with: + fetch-depth: 0 + path: test/ + + - name: Mock creating a Sentry release in a different directory + uses: ./main + env: + MOCK: true + with: + environment: production + working_directory: ./test \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 8d217e85..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,122 +0,0 @@ -name: Integration Tests - -on: - workflow_run: - workflows: [Build Docker Image] - types: - - completed - -env: - # Variables defined in the repository - SENTRY_ORG: ${{ vars.SENTRY_ORG }} - # For master, we have an environment variable that selects the action-release project - # instead of action-release-prs - # For other branches: https://sentry-ecosystem.sentry.io/releases/?project=4505075304693760 - # For master branch: https://sentry-ecosystem.sentry.io/releases/?project=6576594 - SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }} - -jobs: - lint: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Install - run: yarn install - - - name: Check format - run: yarn format-check - - - name: Lint - run: yarn lint - - - name: Build - run: yarn build - - # You're welcome to make changes on this job as part of your PR in order to test out your changes - # We can always undo the changes once we're satisfied with the results - # - # Secrets on this repo do not get shared with PRs opened on a fork, thus, - # add SENTRY_AUTH_TOKEN as a secret to your fork if you want to use this job. - create-staging-release-per-push: - strategy: - matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] - runs-on: ${{ matrix.os }} - name: Test current action - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Create a staging release - uses: ./ - env: - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - SENTRY_LOG_LEVEL: debug - with: - ignore_missing: true - - runs-on-container: - runs-on: ubuntu-latest - container: - image: node:18.17 - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Create a staging release - uses: ./ - env: - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - SENTRY_LOG_LEVEL: debug - with: - ignore_missing: true - - mock-release: - strategy: - matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] - runs-on: ${{ matrix.os }} - name: Mock a release - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Mock creating a Sentry release - uses: ./ - env: - MOCK: true - with: - environment: production - - mock-release-working-directory: - strategy: - matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] - runs-on: ${{ matrix.os }} - name: Mock a release in a different working directory - steps: - - name: Checkout directory we'll be running from - uses: actions/checkout@v4 - with: - fetch-depth: 0 - path: main/ - - - name: Checkout directory we'll be testing - uses: actions/checkout@v4 - with: - fetch-depth: 0 - path: test/ - - - name: Mock creating a Sentry release in a different directory - uses: ./main - env: - MOCK: true - with: - environment: production - working_directory: ./test diff --git a/docs/development.md b/docs/development.md index d45cc453..5babfd98 100644 --- a/docs/development.md +++ b/docs/development.md @@ -31,7 +31,7 @@ Members of this repo will not have to set anything up since [the integration](ht **Step 1** - Create a branch, make changes -- If possible, add unit and E2E tests (inside `.github/workflows/test.yml`) +- If possible, add unit and E2E tests (inside `.github/workflows/build.yml`) - Run `yarn install` to install deps - Run `yarn build` to build the action - Commit the changes and the build inside `dist/` From ef8b952c7d65b706ecd84eedaaeacd7a53a19630 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 24 Feb 2025 14:29:37 +0100 Subject: [PATCH 15/29] Always install node/npm on non Linux runners, update development docs --- action.yml | 10 +------- docs/development.md | 61 +++++++++++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/action.yml b/action.yml index e1163a3e..916c390e 100644 --- a/action.yml +++ b/action.yml @@ -95,16 +95,8 @@ runs: run: | git config --global --add safe.directory "$GITHUB_WORKSPACE" - - name: Get node and npm versions - if: runner.os == 'macOS' || runner.os == 'Windows' - shell: bash - run: | - echo "NODE_VERSION=$(node -v 2>/dev/null || echo '')" >> $GITHUB_ENV - echo "NPM_VERSION=$(npm -v 2>/dev/null || echo '')" >> $GITHUB_ENV - - name: Setup node - # Only install node if there isn't one already - if: ${{ (runner.os == 'macOS' || runner.os == 'Windows') && (env.NODE_VERSION == '' || env.NPM_VERSION == '') }} + if: runner.os == 'macOS' || runner.os == 'Windows' uses: actions/setup-node@v4 with: # setup-node doesn't allow absolute paths, so we can't diff --git a/docs/development.md b/docs/development.md index 5babfd98..1525cea1 100644 --- a/docs/development.md +++ b/docs/development.md @@ -3,19 +3,35 @@ This document aims to provide guidelines for maintainers and contains information on how to develop and test this action. For info on how to release changes, follow [publishing-a-release](publishing-a-release.md). +The action is a composite GitHub Action. + +On Linux runners, the action executes the underlying JavaScript script +via a Docker image we publish. + +For Mac OS and Windows runners, the action cannot run the Docker image and instead installs +the `@sentry/cli` dependency corresponding to the architecture of the runner and then executes the underlying JavaScript +distribution. + +This split in architecture is done to optimize the run-time of the action but at the same time support non-Linux runners. + +This action runs fastest on Linux runners. + ## Development The action is using `@sentry/cli` under the hood and is written in TypeScript. See `src/main.ts` to get started. Options to the action are exposed via `action.yml`, changes that impact options need to be documented in the `README.md`. -Telemetry for internal development is collected using `@sentry/node`, see `src/telemetry.ts` for utilities. - -## Testing +> [!NOTE] +> Actions have to be exposed in 3 places in `action.yml` +> +> 1. Under the `inputs` field - These are the actual inputs exposed to users +> 2. Under the `env` field inside the `Run docker image` step. All inputs have to be mapped from inputs to `INPUT_X` env variables. +> 3. Under the `env` field inside the `Run Release Action -You can run unit tests with `yarn test`. +Telemetry for internal development is collected using `@sentry/node`, see `src/telemetry.ts` for utilities. -### E2E testing on GitHub's CI +## Development steps > [!NOTE] > Contributors will need to create an internal integration in their Sentry org and need to be an admin. @@ -23,27 +39,24 @@ You can run unit tests with `yarn test`. Members of this repo will not have to set anything up since [the integration](https://sentry-ecosystem.sentry.io/settings/developer-settings/end-to-end-action-release-integration-416eb2/) is already set-up. Just open the PR and you will see [a release created](https://sentry-ecosystem.sentry.io/releases/?project=4505075304693760) for your PR. -### Test your own repo against an action-release PR - -> [!NOTE] -> This assumes that you have gone through the [#Usage](../README.md#usage) section and have managed to get your GitHub repository to have worked with this action. - -**Step 1** +> [!WARNING] +> After you create a branch **ALWAYS** run `yarn bump-docker-tag-from-branch`. +> This is **very important**. You should avoid publishing changes to an already existing docker image, +> especially to docker images tagged with release versions, e.g. `1.11.0`. +> +> **Never** write a version tag into `action.yml` yourself, let the release process handle this. + +1. Create a branch +2. Run `yarn bump-docker-tag-from-branch` to set a docker tag based on your github branch name. This is important so that the action gets its own Docker image, allowing you to test the action in a different repo. +3. Make changes +4. If possible, add unit and E2E tests (inside `.github/workflows/build.yml`) +5. Run `yarn install` to install deps +6. Run `yarn build` to build the action +7. Commit the changes and the build inside `dist/` -- Create a branch, make changes -- If possible, add unit and E2E tests (inside `.github/workflows/build.yml`) -- Run `yarn install` to install deps -- Run `yarn build` to build the action -- Commit the changes and the build inside `dist/` - -**Step 2** -Create a new Sentry project under your existing Sentry org (only this one time). - -**Step 3** -Create an environment variable in GitHub for the branch you release from (e.g. `master`) and define the same variable as a repository variable which all other branches will use (i.e. your PR's branch) +## Testing -**Step 4** -Push to GitHub and the CI will do E2E runs! +You can run unit tests with `yarn test`. ### Troubleshooting From c153c71551d5f1d0536886d6cca8bf6770475953 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 11:54:03 +0100 Subject: [PATCH 16/29] Fail the job if docker tag matches MAJOR.MINOR.PATCH naming --- .github/workflows/build.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 509a91d1..0b3a3ed5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,9 @@ name: Build and Test on: + push: + branches: + - release/** pull_request: types: - opened @@ -39,6 +42,14 @@ jobs: run: | TAG=$(yq '... | select(has("uses") and .uses | test("docker://ghcr.io/getsentry/action-release-image:.*")) | .uses' action.yml | awk -F':' '{print $3}') echo "DOCKER_TAG=$TAG" >> $GITHUB_ENV + + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: DOCKER_TAG ($TAG) is not allowed to match `MAJOR.MINOR.PATCH` inside a pull request." + echo "Please rename the docker tag in `action.yml` and try again." + exit 1 + fi + fi - name: Set up QEMU uses: docker/setup-qemu-action@v3 From b6fba50f69e6883c564b28b1a90473a3ff215df4 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 12:15:24 +0100 Subject: [PATCH 17/29] Some cleanup --- .github/workflows/build.yml | 2 +- dist/index.js | 2 +- docs/development.md | 11 +++++------ package.json | 10 +++++----- scripts/craft-pre-release.sh | 2 +- ...ch-docker-tag.sh => set-docker-tag-from-branch.sh} | 0 6 files changed, 13 insertions(+), 14 deletions(-) rename scripts/{set-branch-docker-tag.sh => set-docker-tag-from-branch.sh} (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0b3a3ed5..1c2139a0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,7 +45,7 @@ jobs: if [[ "${{ github.event_name }}" == "pull_request" ]]; then if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "Error: DOCKER_TAG ($TAG) is not allowed to match `MAJOR.MINOR.PATCH` inside a pull request." + echo "Error: DOCKER_TAG ($TAG) is not allowed to match `MAJOR.MINOR.PATCH` format inside a pull request." echo "Please rename the docker tag in `action.yml` and try again." exit 1 fi diff --git a/dist/index.js b/dist/index.js index 8b46164f..02600044 100644 --- a/dist/index.js +++ b/dist/index.js @@ -123585,7 +123585,7 @@ module.exports = JSON.parse('{"eN":{"H":"https://github.com/elastic/require-in-t /***/ ((module) => { "use strict"; -module.exports = JSON.parse('{"name":"action-release","version":"1.10.5","private":true,"description":"GitHub Action for creating a release on Sentry","main":"dist/index.js","scripts":{"start":"node dist/index.js","build":"ncc build src/main.ts -e @sentry/cli","format":"prettier --write **/*.ts **/*.md","format-check":"prettier --check **/*.ts **/*.md","lint":"eslint src/**/*.ts","test":"jest","all":"yarn run format && yarn run lint && yarn run build && yarn test","bump-docker-tag":"./scripts/set-docker-tag.sh","bump-docker-tag-from-branch":"./scripts/set-branch-docker-tag.sh"},"repository":{"type":"git","url":"git+https://github.com/getsentry/action-release.git"},"keywords":["actions","sentry","release"],"author":"Sentry","license":"MIT","dependencies":{"@actions/core":"^1.11.1","@sentry/node":"^8.54.0","@sentry/cli":"^2.41.1"},"devDependencies":{"@types/jest":"^29.5.6","@types/node":"^20.8.9","@typescript-eslint/parser":"^6.9.0","@vercel/ncc":"^0.38.1","eslint":"^8.52.0","eslint-plugin-github":"^4.10.1","eslint-plugin-jest":"^27.4.3","jest":"^29.7.0","jest-circus":"^29.7.0","js-yaml":"^4.1.0","prettier":"^3.0.3","ts-jest":"^29.1.1","typescript":"^5.2.2"},"volta":{"node":"18.17.0","yarn":"1.22.4"}}'); +module.exports = JSON.parse('{"name":"action-release","version":"1.10.5","private":true,"description":"GitHub Action for creating a release on Sentry","main":"dist/index.js","scripts":{"all":"yarn run format && yarn run lint && yarn run build && yarn test","build":"ncc build src/main.ts -e @sentry/cli","format":"prettier --write **/*.ts **/*.md","format-check":"prettier --check **/*.ts **/*.md","lint":"eslint src/**/*.ts","set-docker-tag":"./scripts/set-docker-tag.sh","set-docker-tag-from-branch":"./scripts/set-docker-tag-from-branch.sh","start":"node dist/index.js","test":"jest"},"repository":{"type":"git","url":"git+https://github.com/getsentry/action-release.git"},"keywords":["actions","sentry","release"],"author":"Sentry","license":"MIT","dependencies":{"@actions/core":"^1.11.1","@sentry/node":"^8.54.0","@sentry/cli":"^2.41.1"},"devDependencies":{"@types/jest":"^29.5.6","@types/node":"^20.8.9","@typescript-eslint/parser":"^6.9.0","@vercel/ncc":"^0.38.1","eslint":"^8.52.0","eslint-plugin-github":"^4.10.1","eslint-plugin-jest":"^27.4.3","jest":"^29.7.0","jest-circus":"^29.7.0","js-yaml":"^4.1.0","prettier":"^3.0.3","ts-jest":"^29.1.1","typescript":"^5.2.2"},"volta":{"node":"18.17.0","yarn":"1.22.4"}}'); /***/ }) diff --git a/docs/development.md b/docs/development.md index 1525cea1..25b797f9 100644 --- a/docs/development.md +++ b/docs/development.md @@ -40,14 +40,13 @@ Telemetry for internal development is collected using `@sentry/node`, see `src/t Members of this repo will not have to set anything up since [the integration](https://sentry-ecosystem.sentry.io/settings/developer-settings/end-to-end-action-release-integration-416eb2/) is already set-up. Just open the PR and you will see [a release created](https://sentry-ecosystem.sentry.io/releases/?project=4505075304693760) for your PR. > [!WARNING] -> After you create a branch **ALWAYS** run `yarn bump-docker-tag-from-branch`. -> This is **very important**. You should avoid publishing changes to an already existing docker image, -> especially to docker images tagged with release versions, e.g. `1.11.0`. -> -> **Never** write a version tag into `action.yml` yourself, let the release process handle this. +> After you create a branch **ALWAYS** run `yarn set-docker-tag-from-branch`. +> This is **very important**. You should avoid publishing changes to an already existing docker image. +> +> Docker tags in action.yml that match `MAJOR.MINOR.PATCH` will be rejected by the CI on pull requests. 1. Create a branch -2. Run `yarn bump-docker-tag-from-branch` to set a docker tag based on your github branch name. This is important so that the action gets its own Docker image, allowing you to test the action in a different repo. +2. Run `yarn set-docker-tag-from-branch` to set a docker tag based on your github branch name. This is important so that the action gets its own Docker image, allowing you to test the action in a different repo. 3. Make changes 4. If possible, add unit and E2E tests (inside `.github/workflows/build.yml`) 5. Run `yarn install` to install deps diff --git a/package.json b/package.json index ccc45b6e..704c2e10 100644 --- a/package.json +++ b/package.json @@ -5,15 +5,15 @@ "description": "GitHub Action for creating a release on Sentry", "main": "dist/index.js", "scripts": { - "start": "node dist/index.js", + "all": "yarn run format && yarn run lint && yarn run build && yarn test", "build": "ncc build src/main.ts -e @sentry/cli", "format": "prettier --write **/*.ts **/*.md", "format-check": "prettier --check **/*.ts **/*.md", "lint": "eslint src/**/*.ts", - "test": "jest", - "all": "yarn run format && yarn run lint && yarn run build && yarn test", - "bump-docker-tag": "./scripts/set-docker-tag.sh", - "bump-docker-tag-from-branch": "./scripts/set-branch-docker-tag.sh" + "set-docker-tag": "./scripts/set-docker-tag.sh", + "set-docker-tag-from-branch": "./scripts/set-docker-tag-from-branch.sh", + "start": "node dist/index.js", + "test": "jest" }, "repository": { "type": "git", diff --git a/scripts/craft-pre-release.sh b/scripts/craft-pre-release.sh index 54c72560..292ace52 100755 --- a/scripts/craft-pre-release.sh +++ b/scripts/craft-pre-release.sh @@ -18,4 +18,4 @@ npm version "${NEW_VERSION}" yarn install && yarn build # Update the docker tag in action.yml -yarn bump-docker-tag "${NEW_VERSION}" +yarn set-docker-tag "${NEW_VERSION}" diff --git a/scripts/set-branch-docker-tag.sh b/scripts/set-docker-tag-from-branch.sh similarity index 100% rename from scripts/set-branch-docker-tag.sh rename to scripts/set-docker-tag-from-branch.sh From e5ae635148ba3df704d91ab4649bc2aabcd9602e Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 13:20:32 +0100 Subject: [PATCH 18/29] Test with major.minor.patch tag --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 916c390e..ff2d8235 100644 --- a/action.yml +++ b/action.yml @@ -84,7 +84,7 @@ runs: INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }} INPUT_DISABLE_TELEMETRY: ${{ inputs.disable_telemetry }} INPUT_DISABLE_SAFE_DIRECTORY: ${{ inputs.disable_safe_directory }} - uses: docker://ghcr.io/getsentry/action-release-image:ab-multiarch-docker + uses: docker://ghcr.io/getsentry/action-release-image:0.0.0 # For actions running on macos or windows runners, we use a composite # action approach which allows us to install the arch specific sentry-cli From e27a574a6ca2046916c454e9f1721d72afb39179 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 13:23:44 +0100 Subject: [PATCH 19/29] Rework error message --- .github/workflows/build.yml | 2 +- action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c2139a0..c75f51ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,7 +45,7 @@ jobs: if [[ "${{ github.event_name }}" == "pull_request" ]]; then if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "Error: DOCKER_TAG ($TAG) is not allowed to match `MAJOR.MINOR.PATCH` format inside a pull request." + echo "Error: DOCKER_TAG $TAG matching format MAJOR.MINOR.PATCH is not allowed inside pull requests." echo "Please rename the docker tag in `action.yml` and try again." exit 1 fi diff --git a/action.yml b/action.yml index ff2d8235..916c390e 100644 --- a/action.yml +++ b/action.yml @@ -84,7 +84,7 @@ runs: INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }} INPUT_DISABLE_TELEMETRY: ${{ inputs.disable_telemetry }} INPUT_DISABLE_SAFE_DIRECTORY: ${{ inputs.disable_safe_directory }} - uses: docker://ghcr.io/getsentry/action-release-image:0.0.0 + uses: docker://ghcr.io/getsentry/action-release-image:ab-multiarch-docker # For actions running on macos or windows runners, we use a composite # action approach which allows us to install the arch specific sentry-cli From 608b1f0196bfa01c9aef1974b2357308588a20d1 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 13:27:56 +0100 Subject: [PATCH 20/29] Update development doc --- .github/workflows/build.yml | 2 +- docs/development.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c75f51ef..7a6cc280 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,7 +46,7 @@ jobs: if [[ "${{ github.event_name }}" == "pull_request" ]]; then if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "Error: DOCKER_TAG $TAG matching format MAJOR.MINOR.PATCH is not allowed inside pull requests." - echo "Please rename the docker tag in `action.yml` and try again." + echo "Please rename the docker tag in action.yml and try again." exit 1 fi fi diff --git a/docs/development.md b/docs/development.md index 25b797f9..5a981a09 100644 --- a/docs/development.md +++ b/docs/development.md @@ -40,10 +40,10 @@ Telemetry for internal development is collected using `@sentry/node`, see `src/t Members of this repo will not have to set anything up since [the integration](https://sentry-ecosystem.sentry.io/settings/developer-settings/end-to-end-action-release-integration-416eb2/) is already set-up. Just open the PR and you will see [a release created](https://sentry-ecosystem.sentry.io/releases/?project=4505075304693760) for your PR. > [!WARNING] -> After you create a branch **ALWAYS** run `yarn set-docker-tag-from-branch`. -> This is **very important**. You should avoid publishing changes to an already existing docker image. +> After you create a branch ALWAYS run yarn set-docker-tag-from-branch. +> This is very important. You should avoid publishing changes to an already existing docker image. > -> Docker tags in action.yml that match `MAJOR.MINOR.PATCH` will be rejected by the CI on pull requests. +> Tags matching MAJOR.MINOR.PATCH (e.g. `1.10.2`) will be automatically rejected. 1. Create a branch 2. Run `yarn set-docker-tag-from-branch` to set a docker tag based on your github branch name. This is important so that the action gets its own Docker image, allowing you to test the action in a different repo. From 3b53d971095f2830e655ff012db8cb9ac25fec31 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 13:54:56 +0100 Subject: [PATCH 21/29] Add logic to commit `master` docker tag on master runs --- .github/workflows/build.yml | 48 ++++++++++++++++++++++--------- .github/workflows/verify-dist.yml | 1 + docs/development.md | 4 +-- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7a6cc280..902ee315 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,14 +1,16 @@ name: Build and Test on: + pull_request: + paths-ignore: + - "**.md" push: branches: + - master - release/** - pull_request: - types: - - opened - - synchronize - - reopened + paths-ignore: + - "**.md" + env: # Variables defined in the repository @@ -38,16 +40,34 @@ jobs: with: fetch-depth: 0 - - name: Extract docker tag from action.yml + - name: Set git user to getsentry-bot + if: github.ref == 'refs/heads/master' run: | - TAG=$(yq '... | select(has("uses") and .uses | test("docker://ghcr.io/getsentry/action-release-image:.*")) | .uses' action.yml | awk -F':' '{print $3}') - echo "DOCKER_TAG=$TAG" >> $GITHUB_ENV - - if [[ "${{ github.event_name }}" == "pull_request" ]]; then - if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "Error: DOCKER_TAG $TAG matching format MAJOR.MINOR.PATCH is not allowed inside pull requests." - echo "Please rename the docker tag in action.yml and try again." - exit 1 + echo "GIT_COMMITTER_NAME=getsentry-bot" >> $GITHUB_ENV; + echo "GIT_AUTHOR_NAME=getsentry-bot" >> $GITHUB_ENV; + echo "EMAIL=bot@sentry.io" >> $GITHUB_ENV; + + - name: Evaluate docker tag + run: | + if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then + echo "DOCKER_TAG=master" >> $GITHUB_ENV + yarn set-docker-tag master + + if ! git diff --quiet action.yml; then + git add action.yml + git commit -m "chore: Set docker tag for master [skip-ci]" + git push + fi + else + TAG=$(yq '... | select(has("uses") and .uses | test("docker://ghcr.io/getsentry/action-release-image:.*")) | .uses' action.yml | awk -F':' '{print $3}') + echo "DOCKER_TAG=$TAG" >> $GITHUB_ENV + + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: DOCKER_TAG $TAG matching format MAJOR.MINOR.PATCH is not allowed inside pull requests." + echo "Please rename the docker tag in action.yml and try again." + exit 1 + fi fi fi diff --git a/.github/workflows/verify-dist.yml b/.github/workflows/verify-dist.yml index e05c1ba2..0d87b5d4 100644 --- a/.github/workflows/verify-dist.yml +++ b/.github/workflows/verify-dist.yml @@ -8,6 +8,7 @@ on: push: branches: - master + - release/** paths-ignore: - "**.md" pull_request: diff --git a/docs/development.md b/docs/development.md index 5a981a09..0a108c9e 100644 --- a/docs/development.md +++ b/docs/development.md @@ -41,8 +41,8 @@ Members of this repo will not have to set anything up since [the integration](ht > [!WARNING] > After you create a branch ALWAYS run yarn set-docker-tag-from-branch. -> This is very important. You should avoid publishing changes to an already existing docker image. -> +> This is very important. You should avoid publishing changes to an already existing docker image. +> > Tags matching MAJOR.MINOR.PATCH (e.g. `1.10.2`) will be automatically rejected. 1. Create a branch From f14eba91e23b7dec7c2cfdeeedbb569261d8740c Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 14:12:14 +0100 Subject: [PATCH 22/29] Allow linting in parallel --- .github/workflows/build.yml | 12 ++++-------- action.yml | 3 ++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 902ee315..3a9cb5d0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,13 +40,6 @@ jobs: with: fetch-depth: 0 - - name: Set git user to getsentry-bot - if: github.ref == 'refs/heads/master' - run: | - echo "GIT_COMMITTER_NAME=getsentry-bot" >> $GITHUB_ENV; - echo "GIT_AUTHOR_NAME=getsentry-bot" >> $GITHUB_ENV; - echo "EMAIL=bot@sentry.io" >> $GITHUB_ENV; - - name: Evaluate docker tag run: | if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then @@ -54,6 +47,10 @@ jobs: yarn set-docker-tag master if ! git diff --quiet action.yml; then + echo "GIT_COMMITTER_NAME=getsentry-bot" >> $GITHUB_ENV; + echo "GIT_AUTHOR_NAME=getsentry-bot" >> $GITHUB_ENV; + echo "EMAIL=bot@sentry.io" >> $GITHUB_ENV; + git add action.yml git commit -m "chore: Set docker tag for master [skip-ci]" git push @@ -102,7 +99,6 @@ jobs: build-args: BUILDKIT_INLINE_CACHE=1 lint: - needs: docker-build runs-on: ubuntu-latest steps: diff --git a/action.yml b/action.yml index 916c390e..918e187e 100644 --- a/action.yml +++ b/action.yml @@ -88,7 +88,8 @@ runs: # For actions running on macos or windows runners, we use a composite # action approach which allows us to install the arch specific sentry-cli - # binary that's needed for the runner. This is slower. + # binary that's needed for the runner. + # This is slower than the docker approach but runs on macos and windows. - name: Mark GitHub workspace a safe directory in git if: ${{ (runner.os == 'macOS' || runner.os == 'Windows') && inputs.disable_safe_directory != 'true' }} shell: bash From 06d803a6c22837f30da6da2593813d737135f452 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 16:58:48 +0100 Subject: [PATCH 23/29] Add pre-commit to the repo --- .pre-commit-config.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..ae2d23ab --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml +- repo: local + hooks: + - id: set-docker-tag-from-branch + name: Set docker tag in action.yml from current git branch + entry: yarn set-docker-tag-from-branch + language: system + pass_filenames: false From a1f335f100744d4a8f5979337694dd6a7cfbcb2f Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 17:08:04 +0100 Subject: [PATCH 24/29] Add Makefile to install pre-commit and yarrn deps --- Makefile | 7 +++++++ docs/development.md | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..cec4431d --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +install: setup-git + yarn install + +setup-git: +ifneq (, $(shell which pre-commit)) + pre-commit install +endif diff --git a/docs/development.md b/docs/development.md index 0a108c9e..1795e130 100644 --- a/docs/development.md +++ b/docs/development.md @@ -1,3 +1,14 @@ +# Pre-requirements + +This setup assumes you have [Yarn][Yarn], [Volta][volta] and [pre-commit][pre-commit] installed. + +After cloning the repo, run + +```bash +# Install or update application dependencies +make +``` + # Development of `getsentry/action-release` This document aims to provide guidelines for maintainers and contains information on how to develop and test this action. @@ -33,13 +44,13 @@ Telemetry for internal development is collected using `@sentry/node`, see `src/t ## Development steps -> [!NOTE] +> [!NOTE] > Contributors will need to create an internal integration in their Sentry org and need to be an admin. > See [#Prerequisites](../README.md#prerequisites). Members of this repo will not have to set anything up since [the integration](https://sentry-ecosystem.sentry.io/settings/developer-settings/end-to-end-action-release-integration-416eb2/) is already set-up. Just open the PR and you will see [a release created](https://sentry-ecosystem.sentry.io/releases/?project=4505075304693760) for your PR. -> [!WARNING] +> [!WARNING] > After you create a branch ALWAYS run yarn set-docker-tag-from-branch. > This is very important. You should avoid publishing changes to an already existing docker image. > From 8a7244707779fe89bf9ecd779dab459a6ba945f7 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 17:16:32 +0100 Subject: [PATCH 25/29] Skip pre-commit in action when committing the master tag back --- .github/workflows/build.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3a9cb5d0..c5db97ff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,20 +45,20 @@ jobs: if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then echo "DOCKER_TAG=master" >> $GITHUB_ENV yarn set-docker-tag master - + if ! git diff --quiet action.yml; then echo "GIT_COMMITTER_NAME=getsentry-bot" >> $GITHUB_ENV; echo "GIT_AUTHOR_NAME=getsentry-bot" >> $GITHUB_ENV; echo "EMAIL=bot@sentry.io" >> $GITHUB_ENV; - + git add action.yml - git commit -m "chore: Set docker tag for master [skip-ci]" + SKIP=set-docker-tag-from-branch git commit -m "chore: Set docker tag for master [skip-ci]" git push fi else TAG=$(yq '... | select(has("uses") and .uses | test("docker://ghcr.io/getsentry/action-release-image:.*")) | .uses' action.yml | awk -F':' '{print $3}') echo "DOCKER_TAG=$TAG" >> $GITHUB_ENV - + if [[ "${{ github.event_name }}" == "pull_request" ]]; then if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "Error: DOCKER_TAG $TAG matching format MAJOR.MINOR.PATCH is not allowed inside pull requests." @@ -205,4 +205,4 @@ jobs: MOCK: true with: environment: production - working_directory: ./test \ No newline at end of file + working_directory: ./test From d7149425341e7eff9dc3b5bfda87873be72b01c6 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 17:19:30 +0100 Subject: [PATCH 26/29] Add note on `yarn set-docker-tag-from-branch` to development doc --- docs/development.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/development.md b/docs/development.md index 1795e130..d8546100 100644 --- a/docs/development.md +++ b/docs/development.md @@ -50,12 +50,6 @@ Telemetry for internal development is collected using `@sentry/node`, see `src/t Members of this repo will not have to set anything up since [the integration](https://sentry-ecosystem.sentry.io/settings/developer-settings/end-to-end-action-release-integration-416eb2/) is already set-up. Just open the PR and you will see [a release created](https://sentry-ecosystem.sentry.io/releases/?project=4505075304693760) for your PR. -> [!WARNING] -> After you create a branch ALWAYS run yarn set-docker-tag-from-branch. -> This is very important. You should avoid publishing changes to an already existing docker image. -> -> Tags matching MAJOR.MINOR.PATCH (e.g. `1.10.2`) will be automatically rejected. - 1. Create a branch 2. Run `yarn set-docker-tag-from-branch` to set a docker tag based on your github branch name. This is important so that the action gets its own Docker image, allowing you to test the action in a different repo. 3. Make changes @@ -64,6 +58,9 @@ Members of this repo will not have to set anything up since [the integration](ht 6. Run `yarn build` to build the action 7. Commit the changes and the build inside `dist/` +If you forget to run `yarn set-docker-tag-from-branch` the repo's pre-commit hooks will do it for you and fail the commit. +Just add the changes to staging and commit again. + ## Testing You can run unit tests with `yarn test`. From 879e598d10d73ebe575e660f1346fd9c596723e6 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 17:30:06 +0100 Subject: [PATCH 27/29] Add formatting and linting to pre-commit --- .github/workflows/build.yml | 13 ++++++------- .pre-commit-config.yaml | 21 ++++++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c5db97ff..ca538d00 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,14 +3,13 @@ name: Build and Test on: pull_request: paths-ignore: - - "**.md" + - '**.md' push: branches: - master - release/** paths-ignore: - - "**.md" - + - '**.md' env: # Variables defined in the repository @@ -52,7 +51,7 @@ jobs: echo "EMAIL=bot@sentry.io" >> $GITHUB_ENV; git add action.yml - SKIP=set-docker-tag-from-branch git commit -m "chore: Set docker tag for master [skip-ci]" + SKIP=lint,format,set-docker-tag-from-branch git commit -m "chore: Set docker tag for master [skip-ci]" git push fi else @@ -125,7 +124,7 @@ jobs: needs: docker-build strategy: matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] + os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} name: Test current action steps: @@ -164,7 +163,7 @@ jobs: needs: docker-build strategy: matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] + os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} name: Mock a release steps: @@ -183,7 +182,7 @@ jobs: needs: docker-build strategy: matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] + os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} name: Mock a release in a different working directory steps: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ae2d23ab..7cdf3390 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,16 +1,23 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: -- repo: https://github.com/pre-commit/pre-commit-hooks + - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-yaml -- repo: local + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - repo: local hooks: - - id: set-docker-tag-from-branch + - id: format + name: Format + entry: yarn format + language: system + - id: lint + name: Lint + entry: yarn lint + language: system + - id: set-docker-tag-from-branch name: Set docker tag in action.yml from current git branch entry: yarn set-docker-tag-from-branch language: system - pass_filenames: false From 392ca47577060a4eb7b9e532c9f6aa03cfc9f8cd Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 17:43:09 +0100 Subject: [PATCH 28/29] Mark e2e tests in build.yml better --- .github/workflows/build.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca538d00..fea477a8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -115,12 +115,11 @@ jobs: - name: Build run: yarn build - # You're welcome to make changes on this job as part of your PR in order to test out your changes - # We can always undo the changes once we're satisfied with the results - # - # Secrets on this repo do not get shared with PRs opened on a fork, thus, - # add SENTRY_AUTH_TOKEN as a secret to your fork if you want to use this job. - create-staging-release-per-push: + ############# + # E2E Tests + ############# + + test-create-staging-release-per-push: needs: docker-build strategy: matrix: @@ -140,7 +139,7 @@ jobs: with: ignore_missing: true - runs-on-container: + test-runs-on-container: needs: docker-build runs-on: ubuntu-latest container: @@ -159,7 +158,7 @@ jobs: with: ignore_missing: true - mock-release: + test-mock-release: needs: docker-build strategy: matrix: @@ -178,7 +177,7 @@ jobs: with: environment: production - mock-release-working-directory: + test-mock-release-working-directory: needs: docker-build strategy: matrix: From d68c2d396d4e6dd02a43b6351af033d42f59716a Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 25 Feb 2025 20:15:34 +0100 Subject: [PATCH 29/29] Don't pass filenames to local hooks, fix dockerfile casing --- .pre-commit-config.yaml | 3 +++ Dockerfile | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7cdf3390..4228dc01 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,11 +13,14 @@ repos: name: Format entry: yarn format language: system + pass_filenames: false - id: lint name: Lint entry: yarn lint language: system + pass_filenames: false - id: set-docker-tag-from-branch name: Set docker tag in action.yml from current git branch entry: yarn set-docker-tag-from-branch language: system + pass_filenames: false diff --git a/Dockerfile b/Dockerfile index a7647123..7d526260 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # The multi stage set up *saves* up image size by avoiding the dev dependencies # required to produce dist/ -FROM node:18-alpine as builder +FROM node:18-alpine AS builder WORKDIR /app # This layer will invalidate upon new dependencies COPY package.json yarn.lock ./ @@ -12,7 +12,7 @@ RUN export YARN_CACHE_FOLDER="$(mktemp -d)" \ COPY . . RUN yarn build -FROM node:18-alpine as app +FROM node:18-alpine AS app COPY package.json yarn.lock /action-release/ # On the builder image, we install both types of dependencies rather than # just the production ones. This generates /action-release/node_modules @@ -29,4 +29,4 @@ RUN printf '[safe]\n directory = *\n' > /etc/gitconfig COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/entrypoint.sh"]