Skip to content

feat: Use hybrid docker/composite action approach #265

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

Merged
merged 30 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b39c133
feat: Use hybrid approach depending on runner
andreiborza Feb 24, 2025
facec1c
Fix tag
andreiborza Feb 24, 2025
1cb0224
Update dist
andreiborza Feb 24, 2025
bb834c5
Add fetch depth to test
andreiborza Feb 24, 2025
7102667
Add dependcy on docker-build job for test action
andreiborza Feb 24, 2025
5835751
Improve branch extraction naming, add npm scripts to bump docker tags
andreiborza Feb 24, 2025
35164c1
Pass inputs along
andreiborza Feb 24, 2025
a34995c
Run tests on workflow_run completed
andreiborza Feb 24, 2025
4a0624e
Update workflow run trigger
andreiborza Feb 24, 2025
84831ce
Fix fetch-depth
andreiborza Feb 24, 2025
f820432
Update comment
andreiborza Feb 24, 2025
d3bbc8e
Update workflow naming
andreiborza Feb 24, 2025
4b55e4c
Update workflow names
andreiborza Feb 24, 2025
6c5c926
Merge test.yml into build.yml to run tests after building
andreiborza Feb 24, 2025
ef8b952
Always install node/npm on non Linux runners, update development docs
andreiborza Feb 24, 2025
c153c71
Fail the job if docker tag matches MAJOR.MINOR.PATCH naming
andreiborza Feb 25, 2025
b6fba50
Some cleanup
andreiborza Feb 25, 2025
e5ae635
Test with major.minor.patch tag
andreiborza Feb 25, 2025
e27a574
Rework error message
andreiborza Feb 25, 2025
608b1f0
Update development doc
andreiborza Feb 25, 2025
3b53d97
Add logic to commit `master` docker tag on master runs
andreiborza Feb 25, 2025
f14eba9
Allow linting in parallel
andreiborza Feb 25, 2025
06d803a
Add pre-commit to the repo
andreiborza Feb 25, 2025
a1f335f
Add Makefile to install pre-commit and yarrn deps
andreiborza Feb 25, 2025
8a72447
Skip pre-commit in action when committing the master tag back
andreiborza Feb 25, 2025
d714942
Add note on `yarn set-docker-tag-from-branch` to development doc
andreiborza Feb 25, 2025
879e598
Add formatting and linting to pre-commit
andreiborza Feb 25, 2025
392ca47
Mark e2e tests in build.yml better
andreiborza Feb 25, 2025
d68c2d3
Don't pass filenames to local hooks, fix dockerfile casing
andreiborza Feb 25, 2025
f768c8c
Add changelog
andreiborza Feb 27, 2025
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
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
206 changes: 206 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
name: Build and Test

on:
pull_request:
paths-ignore:
- '**.md'
push:
branches:
- master
- release/**
paths-ignore:
- '**.md'

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
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: 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
echo "GIT_COMMITTER_NAME=getsentry-bot" >> $GITHUB_ENV;
echo "GIT_AUTHOR_NAME=getsentry-bot" >> $GITHUB_ENV;
echo "[email protected]" >> $GITHUB_ENV;

git add action.yml
SKIP=lint,format,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."
echo "Please rename the docker tag in action.yml and try again."
exit 1
fi
fi
fi

- 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

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

#############
# E2E Tests
#############

test-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

test-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

test-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

test-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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Prepare Release
name: "Action: Prepare Release"

on:
workflow_dispatch:
Expand Down
121 changes: 0 additions & 121 deletions .github/workflows/test.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/verify-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
push:
branches:
- master
- release/**
paths-ignore:
- "**.md"
pull_request:
Expand Down
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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: format
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
Loading