Skip to content

Commit

Permalink
[GitHub Actions] Add prepare_git_repo script
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Feb 25, 2020
1 parent c617db1 commit 3ea5a27
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions build_tools/ci/githubactions/prepare_git_repo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.3)
cmake_policy(SET CMP0054 NEW)

# [preparegitrepo.cmake]
#
# Copyright © 2018-2020 pastdue ( https://github.com/past-due/ ) and contributors
# License: MIT License ( https://opensource.org/licenses/MIT )
#

# GitHub Actions: Repo prep
macro(create_all_branches)

# Keep track of where Travis put us.
# We are on a detached head, and we need to be able to go back to it.
execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE build_head
OUTPUT_STRIP_TRAILING_WHITESPACE )
execute_process(COMMAND ${CMAKE_COMMAND} -E echo "build_head: ${build_head}")

# "git fetch --prune"
execute_process(COMMAND ${GIT_EXECUTABLE} fetch --prune --progress)

# also fetch the tags
# "git fetch --tags"
execute_process(COMMAND ${GIT_EXECUTABLE} fetch --tags)

# checkout master to ensure that a local master branch exists
# "git checkout -qf master"
execute_process(COMMAND ${GIT_EXECUTABLE} checkout -qf master)

# finally, go back to where we were at the beginning
# "git checkout -qf ${build_head}"
execute_process(COMMAND ${GIT_EXECUTABLE} checkout -qf ${build_head})

endmacro()

find_package(Git REQUIRED)

if(DEFINED ENV{GITHUB_ACTIONS} AND "$ENV{GITHUB_ACTIONS}" STREQUAL "true")
create_all_branches()
message( STATUS "Prepared GitHub Actions Git repo for autorevision" )
else()
message( WARNING "GitHub Actions environment not detected" )
endif()

0 comments on commit 3ea5a27

Please sign in to comment.