Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 242 additions & 0 deletions .github/workflows/openwrt-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
name: Build OpenWrt Package

on:
workflow_dispatch:
inputs:
openwrt_version:
description: "OpenWrt version"
required: true
default: "23.05.4"
type: choice
options:
- "23.05.4"
- "23.05.3"
- "22.03.7"
target:
description: "Target architecture"
required: true
default: "x86_64"
type: choice
options:
- "x86_64"
- "aarch64_generic"
- "arm_cortex-a9"
- "mips_24kc"
- "mipsel_24kc"
push:
paths:
- 'docs/openwrt/**'
branches:
- main
- master
pull_request:
paths:
- 'docs/openwrt/**'

env:
OPENWRT_VERSION: ${{ github.event.inputs.openwrt_version || '23.05.4' }}
TARGET_ARCH: ${{ github.event.inputs.target || 'x86_64' }}

jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
target:
- x86_64
- aarch64_generic
- arm_cortex-a9
- mips_24kc
- mipsel_24kc

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up environment
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential clang flex bison g++ gawk \
gcc-multilib g++-multilib gettext git libncurses5-dev \
libssl-dev python3-distutils rsync unzip zlib1g-dev \
file wget curl

- name: Setup variables
run: |
echo "OPENWRT_VERSION=${OPENWRT_VERSION}" >> $GITHUB_ENV
echo "TARGET_ARCH=${{ matrix.target }}" >> $GITHUB_ENV
echo "WORK_DIR=${{ github.workspace }}/openwrt" >> $GITHUB_ENV
echo "PACKAGE_DIR=${{ github.workspace }}/openwrt/bin/packages" >> $GITHUB_ENV

case "${{ matrix.target }}" in
x86_64)
echo "SDK_URL_PATH=releases/${OPENWRT_VERSION}/targets/x86/64" >> $GITHUB_ENV
echo "SDK_NAME=openwrt-sdk-${OPENWRT_VERSION}-x86-64_gcc-11.2.0_musl.Linux-x86_64" >> $GITHUB_ENV
;;
aarch64_generic)
echo "SDK_URL_PATH=releases/${OPENWRT_VERSION}/targets/armvirt/64" >> $GITHUB_ENV
echo "SDK_NAME=openwrt-sdk-${OPENWRT_VERSION}-armvirt-64_gcc-11.2.0_musl.Linux-x86_64" >> $GITHUB_ENV
;;
arm_cortex-a9)
echo "SDK_URL_PATH=releases/${OPENWRT_VERSION}/targets/bcm53xx/generic" >> $GITHUB_ENV
echo "SDK_NAME=openwrt-sdk-${OPENWRT_VERSION}-bcm53xx-generic_gcc-11.2.0_musl_eabi.Linux-x86_64" >> $GITHUB_ENV
;;
mips_24kc)
echo "SDK_URL_PATH=releases/${OPENWRT_VERSION}/targets/ath79/generic" >> $GITHUB_ENV
echo "SDK_NAME=openwrt-sdk-${OPENWRT_VERSION}-ath79-generic_gcc-11.2.0_musl.Linux-x86_64" >> $GITHUB_ENV
;;
mipsel_24kc)
echo "SDK_URL_PATH=releases/${OPENWRT_VERSION}/targets/ramips/mt7621" >> $GITHUB_ENV
echo "SDK_NAME=openwrt-sdk-${OPENWRT_VERSION}-ramips-mt7621_gcc-11.2.0_musl.Linux-x86_64" >> $GITHUB_ENV
;;
esac

- name: Cache OpenWrt SDK
id: cache-sdk
uses: actions/cache@v4
with:
path: ${{ env.WORK_DIR }}
key: ${{ runner.os }}-openwrt-sdk-${{ env.OPENWRT_VERSION }}-${{ matrix.target }}

- name: Download and extract OpenWrt SDK
if: steps.cache-sdk.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ env.WORK_DIR }}
cd ${{ env.WORK_DIR }}
wget -q https://downloads.openwrt.org/${{ env.SDK_URL_PATH }}/${{ env.SDK_NAME }}.tar.xz
tar -xf ${{ env.SDK_NAME }}.tar.xz --strip-components=1
rm ${{ env.SDK_NAME }}.tar.xz

- name: Update and install feeds
run: |
cd ${{ env.WORK_DIR }}
./scripts/feeds update -a
./scripts/feeds install -a

- name: Setup Go build environment
run: |
cd ${{ env.WORK_DIR }}

# Add golang feed if not exists
if ! grep -q "src-git golang" feeds.conf.default; then
echo "src-git golang https://github.com/openwrt/packages.git;master" >> feeds.conf.default
./scripts/feeds update golang
./scripts/feeds install -a -p golang
fi

- name: Copy go-drive package
run: |
mkdir -p ${{ env.WORK_DIR }}/package/go-drive
cp -r docs/openwrt/* ${{ env.WORK_DIR }}/package/go-drive/

# Create symbolic link for easier access
ln -sf ${{ github.workspace }} ${{ env.WORK_DIR }}/package/go-drive/go-drive-src

- name: Configure package
run: |
cd ${{ env.WORK_DIR }}

# Enable go-drive packages
echo "CONFIG_PACKAGE_go-drive=m" >> .config
echo "CONFIG_PACKAGE_luci-app-go-drive=m" >> .config

# Enable required dependencies
echo "CONFIG_PACKAGE_golang=y" >> .config
echo "CONFIG_PACKAGE_node=y" >> .config
echo "CONFIG_PACKAGE_npm=y" >> .config

make defconfig

- name: Build package
run: |
cd ${{ env.WORK_DIR }}
make package/go-drive/compile V=s

- name: Organize build artifacts
run: |
mkdir -p ${{ github.workspace }}/artifacts/${{ matrix.target }}
find ${{ env.PACKAGE_DIR }} -name "*go-drive*.ipk" -exec cp {} ${{ github.workspace }}/artifacts/${{ matrix.target }}/ \;

# Create build info
echo "Build Information" > ${{ github.workspace }}/artifacts/${{ matrix.target }}/build-info.txt
echo "===================" >> ${{ github.workspace }}/artifacts/${{ matrix.target }}/build-info.txt
echo "Target: ${{ matrix.target }}" >> ${{ github.workspace }}/artifacts/${{ matrix.target }}/build-info.txt
echo "OpenWrt Version: ${{ env.OPENWRT_VERSION }}" >> ${{ github.workspace }}/artifacts/${{ matrix.target }}/build-info.txt
echo "Build Date: $(date)" >> ${{ github.workspace }}/artifacts/${{ matrix.target }}/build-info.txt
echo "Commit: ${{ github.sha }}" >> ${{ github.workspace }}/artifacts/${{ matrix.target }}/build-info.txt

ls -la ${{ github.workspace }}/artifacts/${{ matrix.target }}/

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: go-drive-openwrt-${{ matrix.target }}
path: ${{ github.workspace }}/artifacts/${{ matrix.target }}/*
retention-days: 30

release:
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && contains(github.ref, 'refs/tags/'))
needs: build
runs-on: ubuntu-22.04
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Create release assets
run: |
mkdir -p release
for target in x86_64 aarch64_generic arm_cortex-a9 mips_24kc mipsel_24kc; do
if [ -d "artifacts/go-drive-openwrt-${target}" ]; then
cd "artifacts/go-drive-openwrt-${target}"
tar -czf "../../release/go-drive-openwrt-${target}.tar.gz" *.ipk build-info.txt
cd ../..
fi
done

ls -la release/

- name: Generate release notes
run: |
echo "# Go-Drive OpenWrt Packages" > release-notes.md
echo "" >> release-notes.md
echo "Auto-generated OpenWrt packages for Go-Drive." >> release-notes.md
echo "" >> release-notes.md
echo "## Supported Architectures" >> release-notes.md
echo "" >> release-notes.md
for target in x86_64 aarch64_generic arm_cortex-a9 mips_24kc mipsel_24kc; do
if [ -f "release/go-drive-openwrt-${target}.tar.gz" ]; then
echo "- ${target}" >> release-notes.md
fi
done
echo "" >> release-notes.md
echo "## Installation" >> release-notes.md
echo "" >> release-notes.md
echo "1. Download the appropriate package for your router architecture" >> release-notes.md
echo "2. Extract the tar.gz file to get the .ipk files" >> release-notes.md
echo "3. Upload and install the .ipk files via LuCI or opkg" >> release-notes.md
echo "" >> release-notes.md
echo "## Build Information" >> release-notes.md
echo "" >> release-notes.md
echo "- OpenWrt Version: ${{ env.OPENWRT_VERSION }}" >> release-notes.md
echo "- Build Date: $(date)" >> release-notes.md
echo "- Commit: ${{ github.sha }}" >> release-notes.md

- name: Create Release
if: github.event_name == 'workflow_dispatch'
uses: softprops/action-gh-release@v1
with:
tag_name: openwrt-${{ github.run_number }}
name: OpenWrt Packages - Build ${{ github.run_number }}
body_path: release-notes.md
files: release/*.tar.gz
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107 changes: 107 additions & 0 deletions docs/openwrt/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#
# Copyright (C) 2024 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=go-drive
PKG_VERSION:=1.0.0
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/devld/go-drive.git
PKG_SOURCE_VERSION:=HEAD
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz

PKG_MAINTAINER:=Go-Drive Team
PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=LICENSE

PKG_BUILD_DEPENDS:=golang/host node/host
PKG_BUILD_PARALLEL:=1
PKG_USE_MIPS16:=0

GO_PKG:=go-drive
GO_PKG_EXCLUDES:=vendor
GO_PKG_BUILD_PKG:=go-drive

include $(INCLUDE_DIR)/package.mk
include ../../lang/golang/golang-package.mk

define Package/go-drive
SECTION:=net
CATEGORY:=Network
SUBMENU:=Cloud Manager
TITLE:=A powerful cloud drive service
URL:=https://github.com/devld/go-drive
DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle
endef

define Package/go-drive/description
Go-Drive is a powerful cloud drive service that supports multiple storage
backends including local storage, OneDrive, Google Drive, and more.
It provides a modern web interface and RESTful API for file management.
endef

define Package/go-drive/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(GO_PKG_BUILD_BIN_DIR)/go-drive $(1)/usr/bin/

$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/etc/config/go-drive $(1)/etc/config/

$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/etc/init.d/go-drive $(1)/etc/init.d/

$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/etc/uci-defaults/go-drive $(1)/etc/uci-defaults/

$(INSTALL_DIR) $(1)/usr/share/go-drive/web
$(CP) $(PKG_BUILD_DIR)/web/dist/* $(1)/usr/share/go-drive/web/

$(INSTALL_DIR) $(1)/usr/share/go-drive/lang
$(CP) $(PKG_BUILD_DIR)/docs/lang/* $(1)/usr/share/go-drive/lang/

$(INSTALL_DIR) $(1)/etc/go-drive
$(INSTALL_CONF) $(PKG_BUILD_DIR)/docs/config.yml $(1)/etc/go-drive/config.yml.example
endef

define Package/luci-app-go-drive
SECTION:=luci
CATEGORY:=LuCI
SUBMENU:=3. Applications
TITLE:=LuCI Support for Go-Drive
DEPENDS:=+go-drive +luci-base
endef

define Package/luci-app-go-drive/description
LuCI web interface for Go-Drive cloud storage service.
Allows configuration and management of Go-Drive through OpenWrt's web interface.
endef

define Package/luci-app-go-drive/install
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
$(INSTALL_DATA) ./luci-app-go-drive/luasrc/controller/go-drive.lua $(1)/usr/lib/lua/luci/controller/

$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi
$(INSTALL_DATA) ./luci-app-go-drive/luasrc/model/cbi/go-drive.lua $(1)/usr/lib/lua/luci/model/cbi/

$(INSTALL_DIR) $(1)/www/luci-static/resources/view
$(INSTALL_DATA) ./luci-app-go-drive/htdocs/luci-static/resources/view/go-drive.js $(1)/www/luci-static/resources/view/

$(INSTALL_DIR) $(1)/usr/share/luci/menu.d
$(INSTALL_DATA) ./luci-app-go-drive/root/usr/share/luci/menu.d/luci-app-go-drive.json $(1)/usr/share/luci/menu.d/
endef

define Build/Compile
cd $(PKG_BUILD_DIR)/web && npm install && npm run build
$(call GoPackage/Build/Compile)
endef

$(eval $(call GoBinPackage,go-drive))
$(eval $(call BuildPackage,go-drive))
$(eval $(call BuildPackage,luci-app-go-drive))
Loading
Loading