From a4a7ed0963bf4c6808957ca62c06825df9edb113 Mon Sep 17 00:00:00 2001 From: Alexander Osadchy Date: Sat, 26 Nov 2022 13:44:47 +0300 Subject: [PATCH 1/5] update github workflows --- .github/workflows/cmake.yml | 10 +-- .github/workflows/process-new-branch.yml | 79 ++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/process-new-branch.yml diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 8edc6ff..b81c7b9 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -5,10 +5,6 @@ on: branches: - master - release/* - pull_request: - branches: - - master - - release/* env: BUILD_TYPE: Release @@ -33,6 +29,12 @@ jobs: shell: bash run: cmake --build . --config $BUILD_TYPE + test: + runs-on: ubuntu-latest + + needs: build + + steps: - name: Test working-directory: ${{github.workspace}}/build shell: bash diff --git a/.github/workflows/process-new-branch.yml b/.github/workflows/process-new-branch.yml new file mode 100644 index 0000000..d6bc8a2 --- /dev/null +++ b/.github/workflows/process-new-branch.yml @@ -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.'); + } From 8031146347ae0d5c94af72716365d49e11333a44 Mon Sep 17 00:00:00 2001 From: Alexander Osadchy Date: Sat, 26 Nov 2022 13:47:04 +0300 Subject: [PATCH 2/5] enable cmake workflow on pull requests --- .github/workflows/cmake.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b81c7b9..10ba237 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -5,6 +5,10 @@ on: branches: - master - release/* + pull_request: + branches: + - master + - release/* env: BUILD_TYPE: Release From c6ce42416beeed4b93787c9325b246d82b214adb Mon Sep 17 00:00:00 2001 From: Alexander Osadchy Date: Sat, 26 Nov 2022 13:50:14 +0300 Subject: [PATCH 3/5] rename cmake workflow to build-and-test --- .github/workflows/{cmake.yml => build-and-test.yml} | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) rename .github/workflows/{cmake.yml => build-and-test.yml} (91%) diff --git a/.github/workflows/cmake.yml b/.github/workflows/build-and-test.yml similarity index 91% rename from .github/workflows/cmake.yml rename to .github/workflows/build-and-test.yml index 10ba237..4259946 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/build-and-test.yml @@ -1,4 +1,4 @@ -name: CMake +name: Build And Test on: push: @@ -33,12 +33,6 @@ jobs: shell: bash run: cmake --build . --config $BUILD_TYPE - test: - runs-on: ubuntu-latest - - needs: build - - steps: - name: Test working-directory: ${{github.workspace}}/build shell: bash From ac10855f34b8ee0100fbbeaefda593b2ac48ed7c Mon Sep 17 00:00:00 2001 From: Alexander Osadchy Date: Sat, 26 Nov 2022 13:51:12 +0300 Subject: [PATCH 4/5] rename workflow job --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 4259946..74c4d71 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -14,7 +14,7 @@ env: BUILD_TYPE: Release jobs: - build: + build-and-test: runs-on: ubuntu-latest steps: From 4b59f9e7f2c245e595ee4dd5f69bda1c1d270855 Mon Sep 17 00:00:00 2001 From: Alexander Osadchy Date: Mon, 28 Nov 2022 10:27:30 +0300 Subject: [PATCH 5/5] indentation fix --- .github/workflows/build-and-test.yml | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 74c4d71..2b4c516 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -18,22 +18,22 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Create Build Environment - run: cmake -E make_directory ${{github.workspace}}/build + - 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: 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: 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 + - name: Test + working-directory: ${{github.workspace}}/build + shell: bash + run: ctest -C $BUILD_TYPE --output-on-failure