diff --git a/.drone.yml b/.drone.yml index 8957592..c967404 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,128 +1,119 @@ kind: pipeline type: kubernetes -name: Build on Multiple Distributions +name: multi-distro-build steps: - - name: clone-repo - image: alpine/git:latest - commands: - - git clone https://gitea.akshun-lab.uk/akshun/setup-script.git /artifacts - volumes: - - name: artifacts - path: /artifacts +- name: clone + image: alpine/git:latest + commands: + - git clone https://gitea.akshun-lab.uk/akshun/setup-script.git /artifacts + volumes: + - name: artifacts + path: /artifacts - - name: parallel-builds - parallel: - # Arch Linux build - - name: build-on-arch - image: archlinux:latest - commands: - - pacman -Syu --noconfirm - - pacman -S --noconfirm git python python-pip binutils - - mv /lib/python3*/EXTERNALLY-MANAGED . - - pip install --upgrade pip - - pip install pyinstaller inquirerpy distro - - cd /artifacts - - pyinstaller --onefile --add-data "bash/:bash/" --add-data "prompts/:prompts/" --add-data "config/:config/" setup.py - - cp /artifacts/dist/setup /artifacts/arch-setup - volumes: - - name: artifacts - path: /artifacts +- name: build-arch + image: archlinux:latest + depends_on: [clone] + commands: + - pacman -Syu --noconfirm + - pacman -S --noconfirm git python python-pip binutils + - mv /lib/python3*/EXTERNALLY-MANAGED . + - pip install --upgrade pip + - pip install pyinstaller inquirerpy distro + - cd /artifacts + - pyinstaller --onefile --add-data "bash/:bash/" --add-data "prompts/:prompts/" --add-data "config/:config/" setup.py + - cp /artifacts/dist/setup /artifacts/arch-setup + volumes: + - name: artifacts + path: /artifacts - # Debian build - - name: build-on-debian - image: debian:stable-slim - commands: - - apt-get update && apt-get upgrade -y - - apt-get install -y git python3 python3-pip binutils - - mv /usr/lib/python*/EXTERNALLY-MANAGED . - - pip install pyinstaller inquirerpy distro - - cd /artifacts - - pyinstaller --onefile --add-data "bash/:bash/" --add-data "prompts/:prompts/" --add-data "config/:config/" setup.py - - cp /artifacts/dist/setup /artifacts/debian-setup - volumes: - - name: artifacts - path: /artifacts +- name: build-debian + image: debian:stable-slim + depends_on: [clone] + commands: + - apt-get update && apt-get upgrade -y + - apt-get install -y git python3 python3-pip binutils + - mv /usr/lib/python*/EXTERNALLY-MANAGED . + - pip install pyinstaller inquirerpy distro + - cd /artifacts + - pyinstaller --onefile --add-data "bash/:bash/" --add-data "prompts/:prompts/" --add-data "config/:config/" setup.py + - cp /artifacts/dist/setup /artifacts/debian-setup + volumes: + - name: artifacts + path: /artifacts - # Fedora build - - name: build-on-fedora - image: fedora:latest - commands: - - dnf update -y - - dnf install -y git python python-pip binutils - - pip install inquirerpy distro pyinstaller - - cd /artifacts - - pyinstaller --onefile --add-data "bash/:bash/" --add-data "prompts/:prompts/" --add-data "config/:config/" setup.py - - cp /artifacts/dist/setup /artifacts/fedora-setup - volumes: - - name: artifacts - path: /artifacts +- name: build-fedora + image: fedora:latest + depends_on: [clone] + commands: + - dnf update -y + - dnf install -y git python python-pip binutils + - pip install inquirerpy distro pyinstaller + - cd /artifacts + - pyinstaller --onefile --add-data "bash/:bash/" --add-data "prompts/:prompts/" --add-data "config/:config/" setup.py + - cp /artifacts/dist/setup /artifacts/fedora-setup + volumes: + - name: artifacts + path: /artifacts - - name: upload-to-gitea - image: alpine/curl:latest - commands: - - apk add --no-cache curl jq - - | - # Ensure required variables are set - if [ -z "$GITEA_TOKEN" ] || [ -z "$GITEA_SERVER" ]; then - echo "Error: GITEA_TOKEN or GITEA_SERVER not set" - exit 1 - fi +- name: upload + image: alpine/curl:latest + depends_on: [build-arch, build-debian, build-fedora] + commands: + - apk add --no-cache curl jq + - | + if [ -z "$GITEA_TOKEN" ] || [ -z "$GITEA_SERVER" ]; then + echo "Error: GITEA_TOKEN or GITEA_SERVER not set" + exit 1 + fi - # 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 - if [ -n "${DRONE_TAG}" ]; then - echo "Creating release for tag ${DRONE_TAG}" + if [ -n "${DRONE_TAG}" ]; then + 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" + 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 + echo "Creating new draft release" 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"}' \ + -d '{"tag_name": "continuous", "name": "Continuous Build", "draft": true, "body": "Automated continuous build"}' \ "$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 + + release_id=$(echo "$response" | jq -r '.id') + fi - # Upload artifacts - for artifact in /artifacts/*-setup; do - if [ -f "$artifact" ]; then - filename=$(basename "$artifact") - echo "Uploading $filename to Gitea release $release_id" - curl -X POST \ - -H "Authorization: token $GITEA_TOKEN" \ - -H "Content-Type: multipart/form-data" \ - -F "attachment=@$artifact" \ - "$GITEA_SERVER/api/v1/repos/$REPO_PATH/releases/$release_id/assets?name=$filename" - else - echo "No artifacts found matching /artifacts/*-setup" - fi - done - environment: - GITEA_TOKEN: - from_secret: gitea-token - GITEA_SERVER: - from_secret: gitea-server - volumes: - - name: artifacts - path: /artifacts + for artifact in /artifacts/*-setup; do + if [ -f "$artifact" ]; then + filename=$(basename "$artifact") + echo "Uploading $filename" + curl -X POST \ + -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: multipart/form-data" \ + -F "attachment=@$artifact" \ + "$GITEA_SERVER/api/v1/repos/$REPO_PATH/releases/$release_id/assets?name=$filename" + fi + done + environment: + GITEA_TOKEN: + from_secret: gitea-token + GITEA_SERVER: + from_secret: gitea-server + volumes: + - name: artifacts + path: /artifacts volumes: - - name: artifacts - temp: {} \ No newline at end of file +- name: artifacts + temp: {} \ No newline at end of file