Skip to content

Commit 6a76b88

Browse files
authored
feat: Use hybrid docker/composite action approach (#265)
* feat: Use hybrid approach depending on runner * Fix tag * Update dist * Add fetch depth to test * Add dependcy on docker-build job for test action * Improve branch extraction naming, add npm scripts to bump docker tags * Pass inputs along * Run tests on workflow_run completed * Update workflow run trigger * Fix fetch-depth * Update comment * Update workflow naming * Update workflow names * Merge test.yml into build.yml to run tests after building * Always install node/npm on non Linux runners, update development docs * Fail the job if docker tag matches MAJOR.MINOR.PATCH naming * Some cleanup * Test with major.minor.patch tag * Rework error message * Update development doc * Add logic to commit `master` docker tag on master runs * Allow linting in parallel * Add pre-commit to the repo * Add Makefile to install pre-commit and yarrn deps * Skip pre-commit in action when committing the master tag back * Add note on `yarn set-docker-tag-from-branch` to development doc * Add formatting and linting to pre-commit * Mark e2e tests in build.yml better * Don't pass filenames to local hooks, fix dockerfile casing * Add changelog
1 parent 15847b6 commit 6a76b88

17 files changed

+414
-166
lines changed

.dockerignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Docs: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# These files will be ignore by Docker for COPY and ADD commands when creating a build context
3+
# In other words, if a file should not be inside of the Docker container it should be
4+
# added to the list, otherwise, it will invalidate cache layers and have to rebuild
5+
# all layers after a COPY command
6+
.git
7+
.github
8+
Dockerfile
9+
.dockerignore
10+
*.md

.github/workflows/build.yml

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
name: Build and Test
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- '**.md'
7+
push:
8+
branches:
9+
- master
10+
- release/**
11+
paths-ignore:
12+
- '**.md'
13+
14+
env:
15+
# Variables defined in the repository
16+
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
17+
# For master, we have an environment variable that selects the action-release project
18+
# instead of action-release-prs
19+
# For other branches: https://sentry-ecosystem.sentry.io/releases/?project=4505075304693760
20+
# For master branch: https://sentry-ecosystem.sentry.io/releases/?project=6576594
21+
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
22+
23+
jobs:
24+
docker-build:
25+
name: Build & publish Docker images
26+
runs-on: ubuntu-latest
27+
permissions:
28+
packages: write
29+
strategy:
30+
matrix:
31+
target:
32+
- name: builder
33+
image: action-release-builder-image
34+
- name: app
35+
image: action-release-image
36+
steps:
37+
- name: Checkout repo
38+
uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Evaluate docker tag
43+
run: |
44+
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
45+
echo "DOCKER_TAG=master" >> $GITHUB_ENV
46+
yarn set-docker-tag master
47+
48+
if ! git diff --quiet action.yml; then
49+
echo "GIT_COMMITTER_NAME=getsentry-bot" >> $GITHUB_ENV;
50+
echo "GIT_AUTHOR_NAME=getsentry-bot" >> $GITHUB_ENV;
51+
echo "[email protected]" >> $GITHUB_ENV;
52+
53+
git add action.yml
54+
SKIP=lint,format,set-docker-tag-from-branch git commit -m "chore: Set docker tag for master [skip-ci]"
55+
git push
56+
fi
57+
else
58+
TAG=$(yq '... | select(has("uses") and .uses | test("docker://ghcr.io/getsentry/action-release-image:.*")) | .uses' action.yml | awk -F':' '{print $3}')
59+
echo "DOCKER_TAG=$TAG" >> $GITHUB_ENV
60+
61+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
62+
if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
63+
echo "Error: DOCKER_TAG $TAG matching format MAJOR.MINOR.PATCH is not allowed inside pull requests."
64+
echo "Please rename the docker tag in action.yml and try again."
65+
exit 1
66+
fi
67+
fi
68+
fi
69+
70+
- name: Set up QEMU
71+
uses: docker/setup-qemu-action@v3
72+
73+
- name: Set up Docker Buildx
74+
uses: docker/setup-buildx-action@v3
75+
76+
- name: Login to GitHub Container Registry
77+
uses: docker/login-action@v3
78+
with:
79+
registry: ghcr.io
80+
username: ${{ github.actor }}
81+
password: ${{ secrets.GITHUB_TOKEN }}
82+
83+
# BUILDKIT_INLINE_CACHE creates the image in such a way that you can
84+
# then use --cache-from (think of a remote cache)
85+
# This feature is allowed thanks to using the buildx plugin
86+
#
87+
# There's a COPY command in the builder stage that can easily invalidate the cache
88+
# If you notice, please add more exceptions to .dockerignore since we loose the value
89+
# of using --cache-from on the app stage
90+
- name: Build and push
91+
uses: docker/build-push-action@v6
92+
with:
93+
platforms: linux/amd64,linux/arm64
94+
push: true
95+
tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.target.image }}:${{ env.DOCKER_TAG }}
96+
cache-from: ghcr.io/${{ github.repository_owner }}/${{ matrix.target.image }}:master
97+
target: ${{ matrix.target.name }}
98+
build-args: BUILDKIT_INLINE_CACHE=1
99+
100+
lint:
101+
runs-on: ubuntu-latest
102+
103+
steps:
104+
- uses: actions/checkout@v4
105+
106+
- name: Install
107+
run: yarn install
108+
109+
- name: Check format
110+
run: yarn format-check
111+
112+
- name: Lint
113+
run: yarn lint
114+
115+
- name: Build
116+
run: yarn build
117+
118+
#############
119+
# E2E Tests
120+
#############
121+
122+
test-create-staging-release-per-push:
123+
needs: docker-build
124+
strategy:
125+
matrix:
126+
os: [ubuntu-latest, windows-latest, macos-latest]
127+
runs-on: ${{ matrix.os }}
128+
name: Test current action
129+
steps:
130+
- uses: actions/checkout@v4
131+
with:
132+
fetch-depth: 0
133+
134+
- name: Create a staging release
135+
uses: ./
136+
env:
137+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
138+
SENTRY_LOG_LEVEL: debug
139+
with:
140+
ignore_missing: true
141+
142+
test-runs-on-container:
143+
needs: docker-build
144+
runs-on: ubuntu-latest
145+
container:
146+
image: node:18.17
147+
148+
steps:
149+
- uses: actions/checkout@v4
150+
with:
151+
fetch-depth: 0
152+
153+
- name: Create a staging release
154+
uses: ./
155+
env:
156+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
157+
SENTRY_LOG_LEVEL: debug
158+
with:
159+
ignore_missing: true
160+
161+
test-mock-release:
162+
needs: docker-build
163+
strategy:
164+
matrix:
165+
os: [ubuntu-latest, windows-latest, macos-latest]
166+
runs-on: ${{ matrix.os }}
167+
name: Mock a release
168+
steps:
169+
- uses: actions/checkout@v4
170+
with:
171+
fetch-depth: 0
172+
173+
- name: Mock creating a Sentry release
174+
uses: ./
175+
env:
176+
MOCK: true
177+
with:
178+
environment: production
179+
180+
test-mock-release-working-directory:
181+
needs: docker-build
182+
strategy:
183+
matrix:
184+
os: [ubuntu-latest, windows-latest, macos-latest]
185+
runs-on: ${{ matrix.os }}
186+
name: Mock a release in a different working directory
187+
steps:
188+
- name: Checkout directory we'll be running from
189+
uses: actions/checkout@v4
190+
with:
191+
fetch-depth: 0
192+
path: main/
193+
194+
- name: Checkout directory we'll be testing
195+
uses: actions/checkout@v4
196+
with:
197+
fetch-depth: 0
198+
path: test/
199+
200+
- name: Mock creating a Sentry release in a different directory
201+
uses: ./main
202+
env:
203+
MOCK: true
204+
with:
205+
environment: production
206+
working_directory: ./test

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Prepare Release
1+
name: "Action: Prepare Release"
22

33
on:
44
workflow_dispatch:

.github/workflows/test.yml

-121
This file was deleted.

.github/workflows/verify-dist.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
push:
99
branches:
1010
- master
11+
- release/**
1112
paths-ignore:
1213
- "**.md"
1314
pull_request:

.pre-commit-config.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v5.0.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- repo: local
11+
hooks:
12+
- id: format
13+
name: Format
14+
entry: yarn format
15+
language: system
16+
pass_filenames: false
17+
- id: lint
18+
name: Lint
19+
entry: yarn lint
20+
language: system
21+
pass_filenames: false
22+
- id: set-docker-tag-from-branch
23+
name: Set docker tag in action.yml from current git branch
24+
entry: yarn set-docker-tag-from-branch
25+
language: system
26+
pass_filenames: false

0 commit comments

Comments
 (0)