release v1.0.1

This commit is contained in:
2024-12-03 17:17:04 +06:00
parent 7a40d8d51e
commit 8758ab19ef
13 changed files with 372 additions and 52 deletions

92
shell-code/build-full.sh Normal file
View File

@@ -0,0 +1,92 @@
#!/bin/bash
# REPO=registry.direct-dev.ru/go-lcg
REPO=kuznetcovay/go-lcg
VERSION=$1
if [ -z "$VERSION" ]; then
VERSION=v1.0.1
fi
BRANCH=main
echo ${VERSION} > VERSION.txt
export GOCACHE="${HOME}/.cache/go-build"
# Save the current branch
CURRENT_BRANCH=$(git branch --show-current)
# Function to restore the original branch
function restore_branch {
echo "Restoring original branch: ${CURRENT_BRANCH}"
git checkout "${CURRENT_BRANCH}"
}
# Check if the current branch is different from the target branch
if [ "$CURRENT_BRANCH" != "$BRANCH" ]; then
# Set a trap to restore the branch on exit
trap restore_branch EXIT
echo "Switching to branch: ${BRANCH}"
git checkout ${BRANCH}
fi
# Fetch all tags from the remote repository
git fetch --tags
# Check if the specified version tag exists
if git rev-parse "refs/tags/${VERSION}" >/dev/null 2>&1; then
echo "Tag ${VERSION} already exists. Halting script."
exit 1
fi
# Run go tests
# if ! go test -v -run=^Test; then
# echo "Tests failed. Exiting..."
# exit 1
# fi
mkdir binaries-for-upload
# Build for linux/amd64
docker build -f Dockerfiles/LocalCompile/Dockerfile --target bin-linux --output bin-linux-amd64/ --platform linux/amd64 . ||
{
echo "docker build for amd64 failed. Exiting with code 1."
exit 1
}
cp bin-linux-amd64/lcg "binaries-for-upload/lcg.amd64.${VERSION}"
# Build for linux/arm64
docker build -f Dockerfiles/LocalCompile/Dockerfile --target bin-linux --output bin-linux-arm64/ --platform linux/arm64 . ||
{
echo "docker build for arm64 failed. Exiting with code 1."
exit 1
}
cp bin-linux-arm64/lcg "binaries-for-upload/lcg.arm64.${VERSION}"
# Push multi-platform images
docker buildx build -f Dockerfiles/ImageBuild/Dockerfile --push --platform linux/amd64,linux/arm64 -t ${REPO}:"${VERSION}" . ||
{
echo "docker buildx build --push failed. Exiting with code 1."
exit 1
}
git add -A . ||
{
echo "git add failed. Exiting with code 1."
exit 1
}
git commit -m "release $VERSION" ||
{
echo "git commit failed. Exiting with code 1."
exit 1
}
git tag -a "$VERSION" -m "release $VERSION" ||
{
echo "git tag failed. Exiting with code 1."
exit 1
}
git push -u origin main --tags ||
{
echo "git push failed. Exiting with code 1."
exit 1
}

View File

@@ -0,0 +1,8 @@
#!/bin/bash
docker build -f Dockerfiles/LocalCompile/Dockerfile --target bin-linux --output bin-linux-amd64/ --platform linux/amd64 .
docker build -f Dockerfiles/LocalCompile/Dockerfile --target bin-linux --output bin-linux-arm64/ --platform linux/arm64 .
# in linux setuid
# sudo chown root:root bin-linux/go-ansible-vault
# sudo chmod +s bin-linux/go-ansible-vault

View File

@@ -0,0 +1,41 @@
#!/bin/bash
REPO=kuznetcovay/go-ansible-vault
VERSION=$1
if [ -z "$VERSION" ]; then
VERSION=v1.0.8
fi
BRANCH=main
echo ${VERSION} > VERSION.txt
export GOCACHE="${HOME}/.cache/go-build"
# Save the current branch
CURRENT_BRANCH=$(git branch --show-current)
# Function to restore the original branch
function restore_branch {
echo "Restoring original branch: ${CURRENT_BRANCH}"
git checkout "${CURRENT_BRANCH}"
}
# Check if the current branch is different from the target branch
if [ "$CURRENT_BRANCH" != "$BRANCH" ]; then
# Set a trap to restore the branch on exit
trap restore_branch EXIT
echo "Switching to branch: ${BRANCH}"
git checkout ${BRANCH}
fi
# Run go tests
if ! go test -v -run=^Test; then
echo "Tests failed. Exiting..."
exit 1
fi
# Push multi-platform images
docker buildx build --push --platform linux/amd64,linux/arm64 -t ${REPO}:${VERSION} . ||
{
echo "docker buildx build --push failed. Exiting with code 1."
exit 1
}

View File

@@ -0,0 +1,63 @@
#!/bin/bash
# Variables
VERSION_FILE="VERSION.txt"
GITHUB_TOKEN="${GITHUB_TOKEN}" # Replace with your GitHub token
REPO="Direct-Dev-Ru/binaries.git" # Replace with your GitHub username/repo
TAG=go-ansible-vault.$(cat "$VERSION_FILE")
echo $TAG
RELEASE_NAME="Binaries ${TAG}" # Replace with your release title
RELEASE_DIR="/home/su/projects/golang/ansible-vault/binaries-for-upload"
# Create a new release
# response=$(curl -s -X POST \
# -H "Authorization: Bearer ${GITHUB_TOKEN}" \
# -H "Accept: application/vnd.github+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://api.github.com/repos/$REPO/releases \
# -d "{\"tag_name\": \"$TAG\", \"name\": \"$RELEASE_NAME\"}")
body="{\"tag_name\":\"${TAG}\", \"target_commitish\":\"main\", \"name\":\"${TAG}\", \
\"body\":\"${TAG}\", \"draft\":false, \"prerelease\":false, \"generate_release_notes\":false}"
echo $body
response=$(curl -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/direct-dev-ru/binaries/releases \
-d $body)
echo $response
# Extract the upload URL from the response
upload_url=$(echo "$response" | jq -r '.upload_url' | sed "s/{?name,label}//")
# Check if the release was created successfully
if [[ "$response" == *"Not Found"* ]]; then
echo "Error: Repository not found or invalid token."
exit 1
fi
# Upload each binary file
for file in "$RELEASE_DIR"/*; do
if [[ -f "$file" ]]; then
filename=$(basename "$file")
echo "Uploading $filename..."
response=$(curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
"$upload_url?name=$filename" \
--data-binary @"$file")
echo $response
fi
done
echo "All binaries uploaded successfully."