Skip to content

Commit

Permalink
v0.2.2 feature complete
Browse files Browse the repository at this point in the history
 - automating everything... at least trying to...
  • Loading branch information
bodand committed Dec 30, 2022
1 parent 7f59f29 commit e23075c
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 53 deletions.
84 changes: 84 additions & 0 deletions .cirrus.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
load('cirrus', 'env', 'http')


def on_build_completed(_ctx):
completed_release(_ctx)


def on_build_failed(_ctx):
failed_release(_ctx)


def failed_release(_ctx):
if env.get("CIRRUS_TAG") != None:
delete_current_release()


def completed_release(_ctx):
if env.get("CIRRUS_TAG") != None:
finish_current_release()


def repo_path():
return "/repos/bodand/cg3"


def delete_current_release():
"""Deletes the current release."""
rel_id = get_current_release()
print("deleting release with id {}".format(rel_id))
delete_release(rel_id)


def finish_current_release():
"""Updates the current release from draft to complete release."""
rel_id = get_current_release()
print("finishing release with id {}".format(rel_id))
return finish_release(rel_id)


def get_current_release():
releases = github_get(repo_path() + "/releases").json()
for rel in releases:
if rel["draft"]:
print("found draft for tag: '{}', id: '{}'".format(rel["tag_name"], rel["id"]))
return "{}".format(rel["id"])
return None

def delete_release(id):
github_delete(repo_path() + "/releases/" + id)


def finish_release(id):
github_patch(repo_path() + "/releases/" + id, {"draft": False})


def get_github_token():
return env.get("GITHUB_TOKEN")


def github_delete(url):
hdrs = {
"Accept": "application/vnd.github+json",
"Authorization": "Bearer " + get_github_token(),
"X-GitHub-Api-Version": "2022-11-28"
}
http.delete("https://api.github.com" + url, headers=hdrs)


def github_get(url):
hdrs = {
"Accept": "application/vnd.github+json",
"Authorization": "Bearer " + get_github_token(),
"X-GitHub-Api-Version": "2022-11-28"
}
return http.get("https://api.github.com" + url, headers=hdrs)


def github_patch(url, body):
hdrs = {
"Accept": "application/vnd.github+json",
"Authorization": "Bearer " + get_github_token(),
"X-GitHub-Api-Version": "2022-11-28"
}
return http.patch("https://api.github.com" + url, headers=hdrs, json_body=body)
182 changes: 153 additions & 29 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
lnx_failed_remove_tag: &FAIL_TAG_LNX
clean_working_dir_script:
- git clean -f -x -q -d
- git tag -d ${CIRRUS_TAG}
- git push --tags --force

win_failed_remove_tag: &FAIL_TAG_WIN
clean_working_dir_script:
- git clean -f -x -q -d
- git tag -d %CIRRUS_TAG%
- git push --tags --force

lnx_build_template: &BUILD_TEMPLATE_TASK
submodules_script:
- git submodule update --init --recursive
Expand Down Expand Up @@ -74,6 +86,7 @@ windows_test_template: &WINDOWS_TEST_TEMPLATE_TASK
- choco install jq -y
- choco install pandoc -y
- choco install ruby -y
- choco install aria2 -y
- choco install cmake -y
- choco install ninja -y
- gem install asciidoctor
Expand Down Expand Up @@ -141,28 +154,80 @@ linux_deploy_template: &LINUX_DEPLOY_TEMPLATE_TASK
- signify-openbsd -S -es "${CG_PKG_NAME}.sec" -m "${CG_PKG_NAME}.sha256"

gh_create_release_script:
- ci/make_release.sh
- /usr/bin/env sh ci/make_release.sh

gh_release_upload_script:
- cd ${BUILD_PATH}
- ../ci/upload-artefact.sh "${CG_PKG_NAME}.pub"
- ../ci/upload-artefact.sh "${CG_PKG_NAME}.tar.xz" "application/x-gtar"
- ../ci/upload-artefact.sh "${CG_PKG_NAME}.deb" "application/vnd.debian.binary-package"
- ../ci/upload-artefact.sh "${CG_PKG_NAME}.rpm" "application/x-rpm"
- ../ci/upload-artefact.sh "${CG_PKG_NAME}.sha256.sig" "text/plain"

binary_artifacts:
paths:
- ${BUILD_PATH}/${CG_PKG_NAME}.pub
- ${BUILD_PATH}/${CG_PKG_NAME}.tar.xz
- ${BUILD_PATH}/${CG_PKG_NAME}.deb
- ${BUILD_PATH}/${CG_PKG_NAME}.rpm
- ${BUILD_PATH}/${CG_PKG_NAME}.sha256.sig
- /usr/bin/env sh ../ci/upload-artefact.sh "${CG_PKG_NAME}.pub"
- /usr/bin/env sh ../ci/upload-artefact.sh "${CG_PKG_NAME}.tar.xz" "application/x-gtar"
- /usr/bin/env sh ../ci/upload-artefact.sh "${CG_PKG_NAME}.deb" "application/vnd.debian.binary-package"/usr/bin/sh
- /usr/bin/env sh ../ci/upload-artefact.sh "${CG_PKG_NAME}.rpm" "application/x-rpm"
- /usr/bin/env sh ../ci/upload-artefact.sh "${CG_PKG_NAME}.sha256.sig" "text/plain"

linux_deployment_task:
only_if: $CIRRUS_BRANCH == 'trunk' && $CIRRUS_TAG != ''
depends_on:
- linux_test
windows_deploy_template: &WINDOWS_DEPLOY_TEMPLATE_TASK
env:
CG_CMAKE_PRESET: win-msvc-${CG_ARCH}-rel
CG_CMAKE_BUILD_PRESET: release-windows-${CG_ARCH}
PATH: C:\ProgramData\chocolatey\bin;C:\tools\ruby31\bin;C:\Program Files\CMake\bin;%CIRRUS_WORKING_DIR%\wix_toolset;%PATH%

dependencies_script:
- choco install visualstudio2022buildtools -y --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest --add Microsoft.Component.VC.Runtime.UCRTSDK --add Microsoft.VisualStudio.Component.Windows10SDK --add Microsoft.VisualStudio.Component.Windows11SDK.22621 --add Microsoft.VisualStudio.Component.VC.ATL"
- choco install vswhere -y
- choco install jq -y
- choco install pandoc -y
- choco install ruby -y
- choco install cmake -y
- choco install aria2 -y
- choco install ninja -y
- choco install curl -y
- gem install asciidoctor
- cmake -E make_directory wix_toolset
- cd wix_toolset
- aria2c https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip -o wix311.zip
- cmake -E tar xzf wix311.zip

<<: *WIN_BUILD_TEMPLATE_TASK

get_signify_script:
- cd %BUILD_PATH%
- aria2c https://github.com/badboy/signify-rs/releases/download/v0.5.3/signify-v0.5.3-x86_64-pc-windows-msvc.zip -o signify.zip
# cmake -E tar is not actually tar; it can handle zip files
- cmake -E tar xzf signify.zip

tarball_package_script:
- cd %BUILD_PATH% && cpack -G TXZ .

package_msi_script:
- cd %BUILD_PATH% && cpack -G WIX .

elevate_package_name_into_env_script:
- ci\package_env.bat

generate_signing_keys_script:
- cd %BUILD_PATH%
- vars.cmd
- signify -G -nc "cg3 %CG_VER% package distribution" -s "%CG_PKG_NAME%.sec" -p "%CG_PKG_NAME%.pub"

sign_packages_script:
- cd %BUILD_PATH%
- vars.cmd
- ..\ci\sha256.bat "%CG_PKG_NAME%.tar.xz" > "%CG_PKG_NAME%.sha256"
- ..\ci\sha256.bat "%CG_PKG_NAME%.msi" >> "%CG_PKG_NAME%.sha256"
- signify -S -es "%CG_PKG_NAME%.sec" -m "%CG_PKG_NAME%.sha256"

gh_create_release_script:
- ci\make_release.bat

gh_release_upload_script:
- cd %BUILD_PATH%
- vars.cmd
- ..\ci\upload-artefact.bat "%CG_PKG_NAME%.pub" "application/octet-stream"
- ..\ci\upload-artefact.bat "%CG_PKG_NAME%.tar.xz" "application/x-gtar"
- ..\ci\upload-artefact.bat "%CG_PKG_NAME%.msi" "application/msword"
- ..\ci\upload-artefact.bat "%CG_PKG_NAME%.sha256.sig" "text/plain"

linux_test_task_tmpl: &LNX_TEST_TMPL
stateful: "false"
container:
image: gcc:latest
cpu: 8
Expand All @@ -174,12 +239,20 @@ linux_deployment_task:
CMAKE_TAR_URL: https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1-linux-x86_64.tar.gz
PATH: /tmp/cirrus-ci-build/cmake-3.25.1-linux-x86_64/bin:${PATH}

<<: *LINUX_DEPLOY_TEMPLATE_TASK
<<: *LINUX_TEST_TEMPLATE_TASK

linux_arm_deployment_task:
only_if: $CIRRUS_BRANCH == 'trunk' && $CIRRUS_TAG != ''
depends_on:
- linux_arm_test
linux_test_task:
only_if: $CIRRUS_TAG == ''

<<: *LNX_TEST_TMPL

linux_deploy_test_task:
only_if: $CIRRUS_TAG != ''

<<: *LNX_TEST_TMPL

linux_arm_test_task_tmpl: &LNX_ARM_TEST_TMPL
stateful: "false"
arm_container:
image: gcc:latest
cpu: 8
Expand All @@ -193,9 +266,22 @@ linux_arm_deployment_task:
CMAKE_TAR_URL: https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1-linux-aarch64.tar.gz
PATH: /tmp/cirrus-ci-build/cmake-3.25.1-linux-aarch64/bin:${PATH}

<<: *LINUX_DEPLOY_TEMPLATE_TASK
<<: *LINUX_TEST_TEMPLATE_TASK

linux_test_task:
linux_arm_test_task:
only_if: $CIRRUS_TAG == ''

<<: *LNX_ARM_TEST_TMPL

linux_arm_deploy_test_task:
only_if: $CIRRUS_TAG != ''

<<: *LNX_ARM_TEST_TMPL

linux_deployment_task:
only_if: $CIRRUS_TAG != ''
depends_on:
- linux_deploy_test
container:
image: gcc:latest
cpu: 8
Expand All @@ -207,9 +293,15 @@ linux_test_task:
CMAKE_TAR_URL: https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1-linux-x86_64.tar.gz
PATH: /tmp/cirrus-ci-build/cmake-3.25.1-linux-x86_64/bin:${PATH}

<<: *LINUX_TEST_TEMPLATE_TASK
<<: *LINUX_DEPLOY_TEMPLATE_TASK

linux_arm_test_task:
on_failure:
<<: *FAIL_TAG_LNX

linux_arm_deployment_task:
only_if: $CIRRUS_TAG != ''
depends_on:
- linux_arm_deploy_test
arm_container:
image: gcc:latest
cpu: 8
Expand All @@ -223,9 +315,13 @@ linux_arm_test_task:
CMAKE_TAR_URL: https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1-linux-aarch64.tar.gz
PATH: /tmp/cirrus-ci-build/cmake-3.25.1-linux-aarch64/bin:${PATH}

<<: *LINUX_TEST_TEMPLATE_TASK
<<: *LINUX_DEPLOY_TEMPLATE_TASK

windows_test_task:
on_failure:
<<: *FAIL_TAG_LNX

windows_test_task_tmpl: &WIN_TEST_TMPL
stateful: "false"
windows_container:
image: cirrusci/windowsservercore:2019
cpu: 8
Expand All @@ -236,3 +332,31 @@ windows_test_task:
BUILD_PATH: _build-release-x64-msvc

<<: *WINDOWS_TEST_TEMPLATE_TASK

windows_test_task:
only_if: $CIRRUS_TAG == ''

<<: *WIN_TEST_TMPL

windows_deploy_test_task:
only_if: $CIRRUS_TAG != ''

<<: *WIN_TEST_TMPL

windows_deployment_task:
only_if: $CIRRUS_TAG != ''
depends_on:
- windows_deploy_test
windows_container:
image: cirrusci/windowsservercore:2019
cpu: 8
memory: 32G

env:
CG_ARCH: x64
BUILD_PATH: _build-release-x64-msvc

<<: *WINDOWS_DEPLOY_TEMPLATE_TASK

on_failure:
<<: *FAIL_TAG_WIN
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ cmake_policy(SET CMP0048 NEW)

# project #########################################################################
project(cg3
VERSION 0.2.1
VERSION 0.2.2
HOMEPAGE_URL "https://github.com/bodand/cg3"
DESCRIPTION "Prog1 homework static checker"
LANGUAGES CXX)
Expand Down Expand Up @@ -269,6 +269,11 @@ install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.adoc"
DESTINATION "${CMAKE_INSTALL_DOCDIR}")

# cpack
if (WIN32)
add_executable(winarch src/util/winarch/main.cxx)
target_compile_options(winarch PRIVATE /EHsc)
target_compile_features(winarch PRIVATE cxx_std_17)
endif ()
get_arch(PACKAGE_ARCH)
if (NOT PACKAGE_ARCH)
message(SEND_ERROR "Could not guess meaningfully about package ISA")
Expand Down
12 changes: 12 additions & 0 deletions changelog/ChangeLog-v0.2.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Cg3 v0.2.2 changelog

## Internal changes

- WIP releases should now be created only as Drafts
- Automate upgrading completed draft releases to complete releases using Starlark
- Automate deleting incomplete releases using Starlark
- Extract all logic from .cirrus.yml into external shell scripts
- Write Windows specific batch/powershell scripts for CI/CD
- Windows CI
- Windows CD
- Releases now contain Windows MSI installers
Loading

0 comments on commit e23075c

Please sign in to comment.