Add logic to commit master docker tag on master runs

This commit is contained in:
Andrei Borza
2025-02-25 14:07:02 +01:00
parent 608b1f0196
commit 3b53d97109
3 changed files with 37 additions and 16 deletions
+34 -14
View File
@@ -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 protected]" >> $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
+1
View File
@@ -8,6 +8,7 @@ on:
push:
branches:
- master
- release/**
paths-ignore:
- "**.md"
pull_request:
+2 -2
View File
@@ -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