Update .drone.yml
Some checks failed
continuous-integration/drone Build is passing
continuous-integration/drone/tag Build was killed

This commit is contained in:
2025-06-16 05:53:39 +00:00
parent e4529610ea
commit ed3cc44eaf

View File

@@ -3,123 +3,126 @@ type: kubernetes
name: Build on Multiple Distributions name: Build on Multiple Distributions
steps: steps:
- name: clone repo - name: clone-repo
image: alpine/git image: alpine/git
commands: commands:
- git clone https://gitea.akshun-lab.uk/akshun/rust-setup.git /artifacts - git clone https://gitea.akshun-lab.uk/akshun/rust-setup.git /artifacts
volumes: volumes:
- name: artifacts - name: artifacts
path: /artifacts path: /artifacts
- name: build on arch - name: build-on-arch
image: archlinux:latest image: archlinux:latest
commands: depends_on: [clone-repo]
- pacman -Syu --noconfirm commands:
- pacman -S --noconfirm rustup gcc - pacman -Syu --noconfirm
- rustup default stable - pacman -S --noconfirm rustup gcc
- cd /artifacts - rustup default stable
- cargo build --release - cd /artifacts
- cp /artifacts/target/release/setup /artifacts/ - cargo build --release
- mv /artifacts/setup /artifacts/arch-setup - cp /artifacts/target/release/setup /artifacts/
volumes: - mv /artifacts/setup /artifacts/arch-setup
- name: artifacts volumes:
path: /artifacts - name: artifacts
path: /artifacts
- name: build on debian - name: build-on-debian
image: debian:stable image: debian:stable
commands: depends_on: [clone-repo]
- apt update && apt upgrade -y commands:
- apt install -y curl gcc - apt update && apt upgrade -y
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - apt install -y curl gcc
- . $HOME/.cargo/env - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- cd /artifacts - . $HOME/.cargo/env
- cargo build --release - cd /artifacts
- cp /artifacts/target/release/setup /artifacts/ - cargo build --release
- mv /artifacts/setup /artifacts/debian-setup - cp /artifacts/target/release/setup /artifacts/
volumes: - mv /artifacts/setup /artifacts/debian-setup
- name: artifacts volumes:
path: /artifacts - name: artifacts
path: /artifacts
- name: build on fedora - name: build-on-fedora
image: fedora:latest image: fedora:latest
commands: depends_on: [clone-repo]
- dnf up -y commands:
- dnf install curl gcc -y - dnf up -y
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - dnf install curl gcc -y
- . $HOME/.cargo/env - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- cd /artifacts - . $HOME/.cargo/env
- cargo build --release - cd /artifacts
- cp /artifacts/target/release/setup /artifacts/ - cargo build --release
- mv /artifacts/setup /artifacts/fedora-setup - cp /artifacts/target/release/setup /artifacts/
volumes: - mv /artifacts/setup /artifacts/fedora-setup
- name: artifacts volumes:
path: /artifacts - name: artifacts
path: /artifacts
- name: upload-to-gitea - name: upload-to-gitea
image: alpine/curl image: alpine/curl
commands: depends_on: [build-on-debian, build-on-arch, build-on-fedora]
- apk add curl jq commands:
- | - apk add curl jq
# Ensure required variables are set - |
if [ -z "$GITEA_TOKEN" ] || [ -z "$GITEA_SERVER" ]; then # Ensure required variables are set
echo "Error: GITEA_TOKEN or GITEA_SERVER not set" if [ -z "$GITEA_TOKEN" ] || [ -z "$GITEA_SERVER" ]; then
exit 1 echo "Error: GITEA_TOKEN or GITEA_SERVER not set"
fi exit 1
fi
# Set repo path (fallback if DRONE_REPO is not set) # Set repo path (fallback if DRONE_REPO is not set)
REPO_PATH="${DRONE_REPO:-akshun/setup-script}" REPO_PATH="${DRONE_REPO:-akshun/setup-script}"
# Create or get release # Create or get release
if [ -n "${DRONE_TAG}" ]; then if [ -n "${DRONE_TAG}" ]; then
echo "Creating release for tag ${DRONE_TAG}" echo "Creating release for tag ${DRONE_TAG}"
response=$(curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"tag_name": "'"${DRONE_TAG}"'", "name": "'"${DRONE_TAG}"'", "body": "Automated release"}' \
"$GITEA_SERVER/api/v1/repos/$REPO_PATH/releases")
release_id=$(echo "$response" | jq -r '.id')
else
echo "Using latest release"
# Try to get latest release
response=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
"$GITEA_SERVER/api/v1/repos/$REPO_PATH/releases/latest" || echo "")
if [ -z "$response" ] || [ "$(echo "$response" | jq -r '.id')" = "null" ]; then
# Create a new draft release if none exists
echo "Creating new draft release"
response=$(curl -s -X POST \ response=$(curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"tag_name": "'"${DRONE_TAG}"'", "name": "'"${DRONE_TAG}"'", "body": "Automated release"}' \ -d '{"tag_name": "continuous", "name": "Continuous Build", "draft": true, "body": "Automated continuous build"}' \
"$GITEA_SERVER/api/v1/repos/$REPO_PATH/releases") "$GITEA_SERVER/api/v1/repos/$REPO_PATH/releases")
release_id=$(echo "$response" | jq -r '.id')
else
echo "Using latest release"
# Try to get latest release
response=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
"$GITEA_SERVER/api/v1/repos/$REPO_PATH/releases/latest" || echo "")
if [ -z "$response" ] || [ "$(echo "$response" | jq -r '.id')" = "null" ]; then
# Create a new draft release if none exists
echo "Creating new draft release"
response=$(curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"tag_name": "continuous", "name": "Continuous Build", "draft": true, "body": "Automated continuous build"}' \
"$GITEA_SERVER/api/v1/repos/$REPO_PATH/releases")
fi
release_id=$(echo "$response" | jq -r '.id')
fi fi
# Upload artifacts release_id=$(echo "$response" | jq -r '.id')
for artifact in /artifacts/*-setup; do fi
if [ -f "$artifact" ]; then
filename=$(basename "$artifact") # Upload artifacts
echo "Uploading $filename to Gitea release $release_id" for artifact in /artifacts/*-setup; do
curl -X POST \ if [ -f "$artifact" ]; then
-H "Authorization: token $GITEA_TOKEN" \ filename=$(basename "$artifact")
-H "Content-Type: multipart/form-data" \ echo "Uploading $filename to Gitea release $release_id"
-F "attachment=@$artifact" \ curl -X POST \
"$GITEA_SERVER/api/v1/repos/$REPO_PATH/releases/$release_id/assets?name=$filename" -H "Authorization: token $GITEA_TOKEN" \
else -H "Content-Type: multipart/form-data" \
echo "No artifacts found matching /artifacts/*-setup" -F "attachment=@$artifact" \
fi "$GITEA_SERVER/api/v1/repos/$REPO_PATH/releases/$release_id/assets?name=$filename"
done else
environment: echo "No artifacts found matching /artifacts/*-setup"
GITEA_TOKEN: fi
from_secret: gitea-token done
GITEA_SERVER: environment:
from_secret: gitea-server GITEA_TOKEN:
volumes: from_secret: gitea-token
- name: artifacts GITEA_SERVER:
path: /artifacts from_secret: gitea-server
volumes:
- name: artifacts
path: /artifacts
volumes: volumes:
- name: artifacts - name: artifacts