From fa72756fedc90f779c3062402d331d98a890e6da Mon Sep 17 00:00:00 2001 From: Thiago Silva Date: Thu, 14 Jul 2022 10:26:10 -0300 Subject: [PATCH] Add a build auto setup job --- .github/workflows/beta_artifacts.yml | 55 ++++++++++++++--- ci/actions/dev-build-tag-gen.sh | 92 ++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 8 deletions(-) create mode 100755 ci/actions/dev-build-tag-gen.sh diff --git a/.github/workflows/beta_artifacts.yml b/.github/workflows/beta_artifacts.yml index d3371e3b2..80f6c7533 100644 --- a/.github/workflows/beta_artifacts.yml +++ b/.github/workflows/beta_artifacts.yml @@ -1,5 +1,7 @@ name: Beta on: + schedule: + - cron: "0 0 * * 6" workflow_dispatch: inputs: repo: @@ -15,19 +17,47 @@ env: artifact: 1 jobs: + build_auto_setup_job: + if: ${{ github.event.inputs.ref == '' }} + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f + with: + ref: "develop" + repository: "nanocurrency/nano-node" + - name: Fetch the repository tags + run: | + git fetch --tags + - name: Generate the new tag + id: tag_gen + run: | + source ci/actions/dev-build-tag-gen.sh + echo "TAG=$build_tag" >> $GITHUB_ENV + - name: Push the new tag + run: | + # Set git configuration + git config user.name "${GITHUB_ACTOR}" + git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" + # Create and push the tag + git tag -a "${TAG}" -m "This tag was automatically generated by the Beta workflow" + git push origin "${TAG}" + osx_job: + if: ${{ github.event.inputs.ref == '' && needs.build_auto_setup_job.result == 'success' && always() || github.event.inputs.ref != '' && always() }} + needs: build_auto_setup_job runs-on: macOS-10.15 timeout-minutes: 90 env: BOOST_ROOT: /tmp/boost steps: - - name: tag + - name: Set the tag + if: ${{ github.event.inputs.ref != '' }} run: | echo "TAG=${{ github.event.inputs.ref }}" >> $GITHUB_ENV - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f with: submodules: "recursive" - ref: ${{ github.event.inputs.ref }} + ref: ${{ env.TAG }} repository: ${{ github.event.inputs.repo }} - name: Fetch Deps run: ci/actions/osx/install_deps.sh @@ -42,16 +72,19 @@ jobs: AWS_DEFAULT_REGION: us-east-2 linux_job: + if: ${{ github.event.inputs.ref == '' && needs.build_auto_setup_job.result == 'success' && always() || github.event.inputs.ref != '' && always() }} + needs: build_auto_setup_job runs-on: ubuntu-20.04 timeout-minutes: 90 steps: - - name: tag + - name: Set the tag + if: ${{ github.event.inputs.ref != '' }} run: | echo "TAG=${{ github.event.inputs.ref }}" >> $GITHUB_ENV - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f with: submodules: "recursive" - ref: ${{ github.event.inputs.ref }} + ref: ${{ env.TAG }} repository: ${{ github.event.inputs.repo }} - name: Fetch Deps env: @@ -68,16 +101,19 @@ jobs: AWS_DEFAULT_REGION: us-east-2 linux_docker_job: + if: ${{ github.event.inputs.ref == '' && needs.build_auto_setup_job.result == 'success' && always() || github.event.inputs.ref != '' && always() }} + needs: build_auto_setup_job runs-on: ubuntu-20.04 timeout-minutes: 90 steps: - - name: tag + - name: Set the tag + if: ${{ github.event.inputs.ref != '' }} run: | echo "TAG=${{ github.event.inputs.ref }}" >> $GITHUB_ENV - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f with: submodules: "recursive" - ref: ${{ github.event.inputs.ref }} + ref: ${{ env.TAG }} repository: ${{ github.event.inputs.repo }} - name: Fetch Deps env: @@ -100,16 +136,19 @@ jobs: run: ci/actions/linux/ghcr_push.sh windows_job: + if: ${{ github.event.inputs.ref == '' && needs.build_auto_setup_job.result == 'success' && always() || github.event.inputs.ref != '' && always() }} + needs: build_auto_setup_job runs-on: windows-latest timeout-minutes: 90 steps: - - name: tag + - name: Set the tag + if: ${{ github.event.inputs.ref != '' }} run: | Write-Output "TAG=${{ github.event.inputs.ref }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f with: submodules: "recursive" - ref: ${{ github.event.inputs.ref }} + ref: ${{ env.TAG }} repository: ${{ github.event.inputs.repo }} - name: Fetch Deps run: ci/actions/windows/install_deps.ps1 diff --git a/ci/actions/dev-build-tag-gen.sh b/ci/actions/dev-build-tag-gen.sh new file mode 100755 index 000000000..e3bf2ea99 --- /dev/null +++ b/ci/actions/dev-build-tag-gen.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# This script gets the last DB tag for the next release version and checks whether the develop branch contains new +# commits since the last develop build. If so, it sets and exports the variable $build_tag with the correct numbering +# for the next DB build. +# Error exit codes: +# 0: success, the build tag was generated! +# 1: branch error or invalid usage of the script. +# 2: no new change found since the last build. + +source_dir="$(pwd)" +git_upstream="origin" + +print_usage() { + echo "$(basename ${0}) [OPTIONS]" + echo "OPTIONS:" + echo " [-h] Print this help info." + echo " [-s ] Directory that contains the source-code. Default is \$PWD." + echo " [-u ] Name of the git repository upstream. Default is \"${git_upstream}\"." +} + +while getopts 'hs:u:' OPT; do + case "${OPT}" in + h) + print_usage + exit 0 + ;; + s) + source_dir="${OPTARG}" + if [[ ! -d "$source_dir" ]]; then + echo "Invalid source directory" + exit 1 + fi + ;; + u) + git_upstream="${OPTARG}" + if [[ -z "$git_upstream" ]]; then + echo "Invalid git upstream" + exit 1 + fi + ;; + *) + print_usage >&2 + exit 1 + ;; + esac +done + +set -o nounset +set -o xtrace + +current_version_major=$(grep -P "(set)(.)*(CPACK_PACKAGE_VERSION_MAJOR)" "${source_dir}/CMakeLists.txt" | grep -oP "([0-9]+)") +current_version_minor=$(grep -P "(set)(.)*(CPACK_PACKAGE_VERSION_MINOR)" "${source_dir}/CMakeLists.txt" | grep -oP "([0-9]+)") +current_version_pre_release=$(grep -P "(set)(.)*(CPACK_PACKAGE_VERSION_PRE_RELEASE)" "${source_dir}/CMakeLists.txt" | grep -oP "([0-9]+)") + +if [[ ${current_version_pre_release} != "99" ]]; then + echo "This is not the develop branch or the pre-release version is not properly set." + exit 1 +fi + +pushd "$source_dir" +last_tag="" +version_tags=$(git tag | sort -r | grep -E "^(V(${current_version_major}).(${current_version_minor})(DB[0-9]+))$") +for tag in $version_tags; do + if [[ -n "$tag" ]]; then + last_tag=$tag + echo "Found tag: $tag" + break + fi +done +popd + +if [[ -z "$last_tag" ]]; then + echo "No tag found" + export build_number=1 + export build_tag="V${current_version_major}.${current_version_minor}DB${build_number}" + exit 0 +fi + +pushd "$source_dir" +develop_head=$(git rev-parse "${git_upstream}/develop") +tag_head=$(git rev-list "$last_tag" | head -n 1) +popd + +if [[ "$develop_head" == "$tag_head" ]]; then + echo "No new commits for the develop build, the develop branch head matches the latest DB tag head!" + exit 2 +fi + +latest_build_number=$(echo "$last_tag" | grep -oP "(DB[0-9]+)" | grep -oP "[0-9]+") +export build_number=$(( latest_build_number + 1 )) +export build_tag="V${current_version_major}.${current_version_minor}DB${build_number}"