Skip to content
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

ci/add-actions-for-new-branches #21

Open
wants to merge 5 commits into
base: release/v0.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build And Test

on:
push:
branches:
- master
- release/*
pull_request:
branches:
- master
- release/*

env:
BUILD_TYPE: Release

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build

- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DUTL_BUILD_TESTS=ON

- name: Build
working-directory: ${{github.workspace}}/build
shell: bash
run: cmake --build . --config $BUILD_TYPE

- name: Test
working-directory: ${{github.workspace}}/build
shell: bash
run: ctest -C $BUILD_TYPE --output-on-failure
39 changes: 0 additions & 39 deletions .github/workflows/cmake.yml

This file was deleted.

79 changes: 79 additions & 0 deletions .github/workflows/process-new-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Process New Branch

on:
create:
branches-ignore:
- 'junk/*'

jobs:
process-new-branch:
runs-on: ubuntu-latest

env:
MASTER_BRANCH: '${{ github.event.repository.default_branch }}'

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Update Project Version
if: ${{ startsWith(github.ref_name, 'release/') }}
run: |
echo '${{ github.ref_name }}' \
| grep -o 'v\([0-9]\+\.\)\{1,3\}\([0-9]\+\)\?$' \
| cut -c 2- \
> .version.new
if [ -s .version.new ]; then
mv .version.new .version
git config --global user.name '${{ github.actor }}'
git config --global user.email '${{ github.actor }}@users.noreply.github.com'
git add .version
git commit -m "[auto] Update .version for a new release branch."
git push
fi

- name: Find Latest Release Branch
id: latest-release
run: |
git for-each-ref \
--format="%(refname:short)" \
--no-merged="origin/${MASTER_BRANCH}" \
'refs/remotes/origin/release/' \
| sort --version-sort --reverse \
| ( cut -c 8- ; echo "${MASTER_BRANCH}" ) \
| ( echo -n "NAME=" ; head -n 1 ) \
>> "$GITHUB_OUTPUT"

- name: Create Pull Request
uses: actions/github-script@v6
with:
script: |
const { owner, repo } = context.repo;
const head = '${{ github.ref_name }}';
const is_release_pr = head.toLowerCase().startsWith('release/');
const base = is_release_pr
? '${{ github.event.repository.default_branch }}'
: '${{ steps.latest-release.outputs.NAME }}';

core.info('Attempting to create pull request.');
core.info('Head branch is: ' + String(head));
core.info('Base branch is: ' + String(base));

try {
const result = await github.rest.pulls.create({
owner,
repo,
title: head,
head: head,
base: base,
draft: is_release_pr
});
core.info('Success!');
} catch(error) {
if (error.message.toLowerCase().search('already exists') == -1) {
throw error;
}
core.info('Such pull request already exists.');
}