From 46b1f35e4a789efb5d09181beb40405cb5015c87 Mon Sep 17 00:00:00 2001 From: Andreas Fertig Date: Mon, 8 Apr 2024 17:51:27 +0200 Subject: [PATCH] Support for automatically building a GitHub release. The idea is to 1) run the `prepare-release.py` script locally to switch to a new Clang version. 2) workflow runs and uploads assets to continuous 3) use the tag `prepare-release` created, update it if necessary, and push it to the remote. --- .github/workflows/ci.yml | 29 +++++++++++++++++++++------ scripts/llvm-coverage.py | 5 +++++ scripts/prepare-release.py | 41 ++++++++++++-------------------------- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ddffd7..82d8f08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,8 @@ on: push: branches-ignore: - 'continuous' + tags: + - 'v_*' pull_request: branches-ignore: @@ -689,12 +691,27 @@ jobs: #------------------------------------------------------------------------------ deploy: needs: [build, docker, in-source-tree] - if: github.ref == 'refs/heads/main' + if: ${{ (github.ref == 'refs/heads/main') || contains(github.ref, 'refs/tags/v_') }} name: Final Deploy continue-on-error: false runs-on: ubuntu-22.04 steps: + - name: Get release info + id: release_info + shell: bash + run: | + tag_name="" + + if [[ "${{ github.ref }}" == *"refs/tags/v_"* ]]; then + tag_name="${{ github.ref_name }}" + else + tag_name="continuous" + fi + + echo "Tag: ${tag_name}" + echo "tag_name=${tag_name}" >> $GITHUB_OUTPUT + - uses: actions/checkout@v4 with: path: cppinsights @@ -720,10 +737,10 @@ jobs: shell: bash run: | cd ${GITHUB_WORKSPACE}/cppinsights - gren changelog --generate --override --username=andreasfertig --repo=cppinsights -t continuous..`git tag --sort=-creatordate | grep -v continuous | head -n 1 ` -c .github/grenrc.json + gren changelog --generate --override --username=andreasfertig --repo=cppinsights -t ${{ steps.release_info.outputs.tag_name }} --limit 1 -c .github/grenrc.json sed -in '1,4d' CHANGELOG.md - - name: Create Release + - name: Create release uses: ncipollo/release-action@v1 with: artifacts: "/home/runner/binaries/insights-artifact-*/insights-*" @@ -731,10 +748,10 @@ jobs: bodyFile: "${{ github.workspace }}/cppinsights/CHANGELOG.md" allowUpdates: true artifactErrorsFailBuild: true - name: continuous - prerelease: true + name: ${{ steps.release_info.outputs.tag_name }} + prerelease: ${{ steps.release_info.outputs.tag_name }} == 'continuous' removeArtifacts: true - tag: continuous + tag: ${{ steps.release_info.outputs.tag_name }} generateReleaseNotes: false - name: Upload docs to gh-pages diff --git a/scripts/llvm-coverage.py b/scripts/llvm-coverage.py index 97a7b59..6f040e7 100755 --- a/scripts/llvm-coverage.py +++ b/scripts/llvm-coverage.py @@ -1,4 +1,9 @@ #! /usr/bin/env python3 +# +# +# C++ Insights, copyright (C) by Andreas Fertig +# Distributed under an MIT license. See LICENSE for details +# #------------------------------------------------------------------------------ import os diff --git a/scripts/prepare-release.py b/scripts/prepare-release.py index a14f0c5..75e3bac 100755 --- a/scripts/prepare-release.py +++ b/scripts/prepare-release.py @@ -14,9 +14,9 @@ def main(): versionH = open('version.h.in', 'r').read() - oldClangStable = '17' - newClangStable = '18' - newInsightsVersion = '18.0' + oldClangStable = '18' + newClangStable = '19' + newInsightsVersion = f'{newClangStable}.0' oldInsightsVersion = re.search(r'INSIGHTS_VERSION\s+"(.*?)"', versionH, re.DOTALL | re.MULTILINE).group(1) @@ -40,7 +40,6 @@ def main(): travis = re.sub(r"(llvm-toolchain-xenial)-(%s)" %(oldClangStable), r"\1-%s" %(newClangStable) , travis) travis = re.sub(r"(./llvm.sh) (%s)" %(oldClangStable), r"\1 %s" %(newClangStable) , travis) -# print(travis) open('.github/workflows/ci.yml', 'w').write(travis) @@ -50,32 +49,23 @@ def main(): open('CMakeLists.txt', 'w').write(cmake) - print(' - Updating version.h %s -> %s' %(oldInsightsVersion, newInsightsVersion)) + print(f' - Updating version.h {oldInsightsVersion} -> {newInsightsVersion}') version = open('version.h.in', 'r').read() version = re.sub('(INSIGHTS_VERSION )"(.*)"', '\\1"%s"' %(newInsightsVersion) , version) open('version.h.in', 'w').write(version) + cppInsightsDockerBaseFile = '../cppinsights-docker-base/Dockerfile' - print(' - Generating CHANGELOG.md') - os.system('gren changelog --override --username=andreasfertig --repo=cppinsights %s...continous' %(oldInsightsVersion)) - - cmd = ['gren', 'changelog', '--override', '--username=andreasfertig', '--repo=cppinsights', '%s...continous' %(oldInsightsVersion)] - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = p.communicate() + print(f' - Updating cppinsights-docker-base ({cppInsightsDockerBaseFile})') - if 0 != p.returncode: - print('ERR: gren failed') - print(stderr) - return 1 + dockerFile = open(cppInsightsDockerBaseFile, 'r').read() + dockerFile = re.sub(r'(ENV\s+CLANG_VERSION=)([0-9]+)', r'\g<1>%s' %(newClangStable), dockerFile) + open(cppInsightsDockerBaseFile, 'w').write(dockerFile) - changeLog = open('CHANGELOG.md', 'r').read() - changeLog = re.sub('(## Continuous build.*?---)\n', '', changeLog, flags=re.DOTALL) - open('CHANGELOG.md', 'w').write(changeLog) - gitTag = 'v_%s' %(oldInsightsVersion) - print(' - Tagging %s' %(gitTag)) + gitTag = f'v_{oldInsightsVersion}' + print(f' - Tagging {gitTag}') - #cmd = ['git', 'tag', '-a', '-m', gitTag, gitTag, 'main'] cmd = ['git', 'tag', gitTag, 'main'] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() @@ -85,13 +75,8 @@ def main(): print(stderr) return 1 - cppInsightsDockerBaseFile = '../cppinsights-docker-base/Dockerfile' - - print(' - Updating cppinsights-docker-base (%s)' %(cppInsightsDockerBaseFile)) - - dockerFile = open(cppInsightsDockerBaseFile, 'r').read() - dockerFile = re.sub(r'(ENV\s+CLANG_VERSION=)([0-9]+)', r'\g<1>%s' %(newClangStable), dockerFile) - open(cppInsightsDockerBaseFile, 'w').write(dockerFile) + print(' - Push tag:') + print(f' git push origin {gitTag}') #------------------------------------------------------------------------------ main()