Skip to content

Merge test changes to main (#386) #435

Merge test changes to main (#386)

Merge test changes to main (#386) #435

name: "Create promotion pull request"
on:
workflow_dispatch:
push:
branches:
- test
- dev
- "feature/**"
- "bugfix/**"
jobs:
promote-test-to-main:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/test'
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Check if PR exists
id: check
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
run: |
ref=$(echo $GITHUB_REF | sed 's/refs\/heads\///g')
echo "ref=$ref"
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--json baseRefName,headRefName \
--jq "map(select(.baseRefName == \"main\" and .headRefName == \"$ref\")) | length")
if ((prs > 0)); then
echo "setting skip true"
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "setting skip false"
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
# If we get "fatal: Invalid revision range id1..id2" we pipe the error to stdout and still get higher than 0,
# which means we fall back to creating a PR if there is an issue by design
diffs=$(git diff --name-status ${{ github.event.before }}..${{ github.event.after }} 2>&1 | wc -l)
echo "diffs=$diffs"
if ((diffs > 0)); then
echo "setting has_diff true"
echo "has_diff=true" >> "$GITHUB_OUTPUT"
else
echo "setting has_diff false"
echo "has_diff=false" >> "$GITHUB_OUTPUT"
fi
- name: Reset promotion branch
if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
run: |
git fetch origin test:test
git reset --hard test
- name: Create Pull Request
id: create-pr
uses: peter-evans/create-pull-request@v7
if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
with:
token: ${{ secrets.WORKFLOW_TOKEN }}
branch: test
title: Merge test changes to main
body: Automatically created pull-request in order to merge changes that were recently pushed to the test branch, back to main
# assignees: hwinther
draft: true
# Not possible if draft: true above
# - name: Set auto merge on pull request
# if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
# env:
# GH_TOKEN: ${{ github.token }}
# PR_URL: ${{ steps.create-pr.outputs.pull-request-url }}
# run: gh pr merge --merge --auto $PR_URL
promote-dev-to-test:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/dev'
steps:
- uses: actions/checkout@v4
with:
ref: test
- name: Check if PR exists
id: check
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
run: |
ref=$(echo $GITHUB_REF | sed 's/refs\/heads\///g')
echo "ref=$ref"
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--json baseRefName,headRefName \
--jq "map(select(.baseRefName == \"test\" and .headRefName == \"$ref\")) | length")
if ((prs > 0)); then
echo "setting skip true"
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "setting skip false"
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
# If we get "fatal: Invalid revision range id1..id2" we pipe the error to stdout and still get higher than 0,
# which means we fall back to creating a PR if there is an issue by design
diffs=$(git diff --name-status ${{ github.event.before }}..${{ github.event.after }} 2>&1 | wc -l)
echo "diffs=$diffs"
if ((diffs > 0)); then
echo "setting has_diff true"
echo "has_diff=true" >> "$GITHUB_OUTPUT"
else
echo "setting has_diff false"
echo "has_diff=false" >> "$GITHUB_OUTPUT"
fi
- name: Reset promotion branch
if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
run: |
git fetch origin dev:dev
git reset --hard dev
- name: Create Pull Request
id: create-pr
uses: peter-evans/create-pull-request@v7
if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
with:
token: ${{ secrets.WORKFLOW_TOKEN }}
branch: dev
title: Merge dev changes to test
body: Automatically created pull-request in order to merge changes that were recently pushed to the dev branch, back to test
# assignees: hwinther
draft: true
# Not possible if draft: true above
# - name: Set auto merge on pull request
# if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
# env:
# GH_TOKEN: ${{ github.token }}
# PR_URL: ${{ steps.create-pr.outputs.pull-request-url }}
# run: gh pr merge --merge --auto $PR_URL
# promote-feature-branch-to-dev:
# runs-on: ubuntu-latest
# if: ${{ contains(github.ref, 'refs/heads/feature/') || contains(github.ref, 'refs/heads/bugfix/') }}
# steps:
# - uses: actions/checkout@v4
# with:
# ref: dev
# - name: Check if PR exists
# id: check
# env:
# GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
# run: |
# ref=$(echo $GITHUB_REF | sed 's/refs\/heads\///g')
# echo "ref=$ref"
# prs=$(gh pr list \
# --repo "$GITHUB_REPOSITORY" \
# --json baseRefName,headRefName \
# --jq "map(select(.baseRefName == \"dev\" and .headRefName == \"$ref\")) | length")
# if ((prs > 0)); then
# echo "setting skip true"
# echo "skip=true" >> "$GITHUB_OUTPUT"
# else
# echo "setting skip false"
# echo "skip=false" >> "$GITHUB_OUTPUT"
# fi
# # If we get "fatal: Invalid revision range id1..id2" we pipe the error to stdout and still get higher than 0,
# # which means we fall back to creating a PR if there is an issue by design
# diffs=$(git diff --name-status ${{ github.event.before }}..${{ github.event.after }} 2>&1 | wc -l)
# echo "diffs=$diffs"
# if ((diffs > 0)); then
# echo "setting has_diff true"
# echo "has_diff=true" >> "$GITHUB_OUTPUT"
# else
# echo "setting has_diff false"
# echo "has_diff=false" >> "$GITHUB_OUTPUT"
# fi
# - name: Reset promotion branch
# if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
# run: |
# git fetch origin ${{ github.ref }}:${{ github.ref }}
# git reset --hard ${{ github.ref }}
# - name: Create Pull Request
# if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# REF: ${{ github.ref }}
# TITLE: ${{ github.event.head_commit.message }}
# run: |
# PR_URL=$(gh pr create --base dev --head $REF --title '${TITLE}' --body-file .github/PULL_REQUEST_TEMPLATE.md)
# gh pr merge --squash --auto $PR_URL