3d_collision_helpers/.forgejo/workflows/release-and-assets.yml

224 lines
12 KiB
YAML
Raw Permalink Normal View History

name: Build for Releases
on:
push:
tags:
- '*'
jobs:
ensure-release-exists:
runs-on: any_archLinux
steps:
- name: Ensure that release exists
id: release_exists
run: |
curl -X GET "https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/tags/${GITHUB_REF_NAME}" \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'accept: application/json' -o release_check_resp.json 2>/dev/null \
-w '%{http_code}\n' | sed 's/^\([0-9]\+\)/http_code=\1/' > check_release_http_code
test "$(cat check_release_http_code)" = "http_code=404" && \
curl --fail-with-body -X 'POST' \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases" \
-H 'accept: application/json' \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'Content-Type: application/json' \
-d "{
\"name\": \"3d_collision_helpers version ${GITHUB_REF_NAME}\",
\"tag_name\": \"${GITHUB_REF_NAME}\",
\"body\": \" SHA256SUMS\"
}" >&/dev/null
assets-release-x86_64:
needs: ensure-release-exists
2024-06-15 02:12:32 +00:00
runs-on: x86_64_archLinux
steps:
- name: Check and push assets
id: check_release_assets_x86_64
run: |
THE_CURRENT_WORKING_DIRECTORY="$(pwd)"
curl -X 'GET' \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/tags/${GITHUB_REF_NAME}" \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'accept: application/json' > release_info.json
jq '.assets.[].name' < release_info.json | tr -d '"' > assets_list
SHARED_LIB_ASSET_NAME="3d_collision_helpers_${GITHUB_REF_NAME}_shared.tar.zst"
STATIC_LIB_ASSET_NAME="3d_collision_helpers_${GITHUB_REF_NAME}_static.tar.zst"
SHARED_LIB_ASSET_EXISTS=0
STATIC_LIB_ASSET_EXISTS=0
for asset in $(cat assets_list); do
if [[ "$asset" == "$SHARED_LIB_ASSET_NAME" ]]; then
SHARED_LIB_ASSET_EXISTS=1
fi
if [[ "$asset" == "$STATIC_LIB_ASSET_NAME" ]]; then
STATIC_LIB_ASSET_EXISTS=1
fi
done
test -d "$THE_CURRENT_WORKING_DIRECTORY/3dcolhelpers_cloned" || git clone --depth=1 --no-single-branch https://${GITHUB_TOKEN}@git.seodisparate.com/stephenseo/3d_collision_helpers.git "$THE_CURRENT_WORKING_DIRECTORY/3dcolhelpers_cloned"
pushd "$THE_CURRENT_WORKING_DIRECTORY/3dcolhelpers_cloned" >&/dev/null
if ! (( SHARED_LIB_ASSET_EXISTS )); then
git clean -xfd && git restore . && git checkout ${GITHUB_REF_NAME}
echo 'Building shared libs...'
cmake -S . -B buildRelease -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=On -DCMAKE_INSTALL_PREFIX=/usr
make -C buildRelease
pushd buildRelease
make DESTDIR=out_shared install
cd out_shared
fakeroot tar --sort=name -cv usr | zstd --ultra -20 > "$THE_CURRENT_WORKING_DIRECTORY/$SHARED_LIB_ASSET_NAME"
popd
curl --fail-with-body -X GET \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/$(jq .id < $THE_CURRENT_WORKING_DIRECTORY/release_info.json)" \
-H 'accept: application/json' \
-o current_release_info.json 2>/dev/null
curl --fail-with-body -X PATCH \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/$(jq .id < $THE_CURRENT_WORKING_DIRECTORY/release_info.json)" \
-H 'accept: application/json' \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'Content-Type: application/json' \
-d "{
\"body\":\"$(jq .body < current_release_info.json | sed -e 's/^"//' -e 's/"$//')
$(find "$THE_CURRENT_WORKING_DIRECTORY" -maxdepth 1 -name "*$SHARED_LIB_ASSET_NAME" -execdir sha256sum '{}' ';' | sed -e 's|\./3d_collision|3d_collision|')\"
}" >&/dev/null
curl --fail-with-body -X POST \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/$(jq .id < $THE_CURRENT_WORKING_DIRECTORY/release_info.json)/assets" \
-H 'accept: application/json' \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'Content-Type: multipart/form-data' \
-F "attachment=@${THE_CURRENT_WORKING_DIRECTORY}/$SHARED_LIB_ASSET_NAME;type=application/zstd" > client_attach.json
fi
if ! (( STATIC_LIB_ASSET_EXISTS )); then
git clean -xfd && git restore . && git checkout ${GITHUB_REF_NAME}
echo 'Building static libs...'
cmake -S . -B buildRelease -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=Off -DCMAKE_INSTALL_PREFIX=/usr
make -C buildRelease
pushd buildRelease
make DESTDIR=out_static install
cd out_static
fakeroot tar --sort=name -cv usr | zstd --ultra -20 > "$THE_CURRENT_WORKING_DIRECTORY/$STATIC_LIB_ASSET_NAME"
popd
curl --fail-with-body -X GET \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/$(jq .id < $THE_CURRENT_WORKING_DIRECTORY/release_info.json)" \
-H 'accept: application/json' \
-o current_release_info.json 2>/dev/null
curl --fail-with-body -X PATCH \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/$(jq .id < $THE_CURRENT_WORKING_DIRECTORY/release_info.json)" \
-H 'accept: application/json' \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'Content-Type: application/json' \
-d "{
\"body\":\"$(jq .body < current_release_info.json | sed -e 's/^"//' -e 's/"$//')
$(find "$THE_CURRENT_WORKING_DIRECTORY" -maxdepth 1 -name "*$STATIC_LIB_ASSET_NAME" -execdir sha256sum '{}' ';' | sed -e 's|\./3d_collision|3d_collision|')\"
}" >&/dev/null
curl --fail-with-body -X POST \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/$(jq .id < $THE_CURRENT_WORKING_DIRECTORY/release_info.json)/assets" \
-H 'accept: application/json' \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'Content-Type: multipart/form-data' \
-F "attachment=@${THE_CURRENT_WORKING_DIRECTORY}/$STATIC_LIB_ASSET_NAME;type=application/zstd" > client_attach.json
fi
assets-release-x86_64-debian:
needs: assets-release-x86_64
if: ${{ always() }}
runs-on: docker_debian_bookworm
env:
SHARED_LIB_ASSET_NAME: "3d_collision_helpers_${{ github.ref_name }}_debian_shared.tar.zst"
STATIC_LIB_ASSET_NAME: "3d_collision_helpers_${{ github.ref_name }}_debian_static.tar.zst"
steps:
- name: Update and upgrade with apt
run: apt-get --yes update && apt-get --yes upgrade
- name: Get necessary packages
run: apt-get --yes install gcc g++ jq curl cmake make zstd sed git
- name: Get release info
run: |
curl -X GET \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/tags/${GITHUB_REF_NAME}" \
-H 'accept: application/json' -o release_info.json
- name: Check if asset exists
run: |
for asset in $(jq '.assets[].name' < release_info.json | tr -d '"'); do
if [[ "$asset" == "$SHARED_LIB_ASSET_NAME" ]]; then
touch shared_lib_exists
elif [[ "$asset" == "$STATIC_LIB_ASSET_NAME" ]]; then
touch static_lib_exists
fi
done
- name: Build shared if asset does not exist
run: |
if ! [[ -e shared_lib_exists ]]; then
if ! [[ -d 3dch_cloned ]]; then
git clone --depth=1 --no-single-branch https://git.seodisparate.com/stephenseo/3d_collision_helpers.git 3dch_cloned
fi
pushd 3dch_cloned >&/dev/null && git restore . && git checkout "${GITHUB_REF_NAME}" && popd >&/dev/null
# Debian's gcc doesn't know about "-fstrict-flex-arrays=3".
sed -i -e 's/-fstrict-flex-arrays=3//g' 3dch_cloned/CMakeLists.txt
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=On -DCMAKE_INSTALL_PREFIX=/usr -S 3dch_cloned -B buildReleaseShared
make -C buildReleaseShared
make DESTDIR=$(pwd)/sharedOut -C buildReleaseShared install
pushd sharedOut >&/dev/null
tar --sort=name -I'zstd --compress -T0 --ultra -20' -cf "$SHARED_LIB_ASSET_NAME" usr
popd >&/dev/null
curl -X GET \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/tags/${GITHUB_REF_NAME}" \
-H 'accept: application/json' -o release_info_latest.json
curl --fail-with-body -X PATCH \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/$(jq .id < release_info_latest.json)" \
-H 'accept: application/json' \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'Content-Type: application/json' \
-d "{
\"body\": \"$(jq .body < release_info_latest.json | sed -e 's/^"//' -e 's/"$//')
$(cd sharedOut && sha256sum "$SHARED_LIB_ASSET_NAME")\"
"} >&/dev/null
curl --fail-with-body -X POST \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/$(jq .id < release_info_latest.json)/assets" \
-H 'accept: application/json' \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'Content-Type: multipart/form-data' \
-F "attachment=@sharedOut/${SHARED_LIB_ASSET_NAME};type=application/zstd" >&/dev/null
fi
- name: Build static if asset does not exist
run: |
if ! [[ -e static_lib_exists ]]; then
if ! [[ -d 3dch_cloned ]]; then
git clone --depth=1 --no-single-branch https://git.seodisparate.com/stephenseo/3d_collision_helpers.git 3dch_cloned
fi
pushd 3dch_cloned >&/dev/null && git restore . && git checkout "${GITHUB_REF_NAME}" && popd >&/dev/null
# Debian's gcc doesn't know about "-fstrict-flex-arrays=3".
sed -i -e 's/-fstrict-flex-arrays=3//g' 3dch_cloned/CMakeLists.txt
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=Off -DCMAKE_INSTALL_PREFIX=/usr -S 3dch_cloned -B buildReleaseStatic
make -C buildReleaseStatic
make DESTDIR=$(pwd)/staticOut -C buildReleaseStatic install
pushd staticOut >&/dev/null
tar --sort=name -I'zstd --compress -T0 --ultra -20' -cf "$STATIC_LIB_ASSET_NAME" usr
popd >&/dev/null
curl -X GET \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/tags/${GITHUB_REF_NAME}" \
-H 'accept: application/json' -o release_info_latest.json
curl --fail-with-body -X PATCH \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/$(jq .id < release_info_latest.json)" \
-H 'accept: application/json' \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'Content-Type: application/json' \
-d "{
\"body\": \"$(jq .body < release_info_latest.json | sed -e 's/^"//' -e 's/"$//')
$(cd staticOut && sha256sum "$STATIC_LIB_ASSET_NAME")\"
"} >&/dev/null
curl --fail-with-body -X POST \
"https://git.seodisparate.com/api/v1/repos/stephenseo/3d_collision_helpers/releases/$(jq .id < release_info_latest.json)/assets" \
-H 'accept: application/json' \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H 'Content-Type: multipart/form-data' \
-F "attachment=@staticOut/${STATIC_LIB_ASSET_NAME};type=application/zstd" >&/dev/null
fi