Skip to content

Commit

Permalink
Add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimkurb committed Nov 11, 2024
1 parent f393d65 commit cf5ed87
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 10 deletions.
168 changes: 168 additions & 0 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: CI

on:
push:
branches:
- main
paths-ignore:
- '.editorconfig'
- '.gitignore'
- 'LICENSE'
- 'README.md'
workflow_dispatch:

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.gh.outputs.version }}
release: ${{ steps.gh.outputs.release }}
sha: ${{ steps.gh.outputs.sha }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: GH
id: gh
env:
REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
echo "version=$(cat Makefile | grep "PKG_VERSION :=" | sed 's/PKG_VERSION := //')" >> $GITHUB_OUTPUT
echo "release=$(cat Makefile | grep "PKG_RELEASE :=" | sed 's/PKG_RELEASE := //')" >> $GITHUB_OUTPUT
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
echo "sha=$(echo ${GITHUB_SHA::7})" >> $GITHUB_OUTPUT
else
echo "sha=$(gh api repos/$REPO/commits/main --jq '.sha[:7]')" >> $GITHUB_OUTPUT
fi
build-entware:
needs: prepare
runs-on: ubuntu-latest
strategy:
matrix:
arch:
# - aarch64-3.10
# - armv7-3.2
# - mips-3.4
- mipsel-3.4
# - x64-3.2
include:
- arch: armv7-2.6
k26: true
- arch: x86-2.6
k26: true
steps:
- name: Set up Entware docker container
run: |
git clone --depth 1 https://github.com/Entware/docker.git
docker build docker --pull --tag builder
docker volume create entware-home
- name: Restore Entware from cache
id: cache-restore
uses: actions/cache/restore@v4
with:
path: ~/entware
key: entware-${{ matrix.arch }}

- name: Load Entware from cache
if: steps.cache-restore.outputs.cache-hit == 'true'
run: |
docker run --rm --mount source=entware-home,target=/backup_vol -v ~/entware:/backup ubuntu tar -xf /backup/entware.tar -C /backup_vol
docker run --rm --mount source=entware-home,target=/home/me -w /home/me ubuntu bash -c 'cp -r ./backup_vol/* ./'
docker run --rm --mount source=entware-home,target=/home/me -w /home/me ubuntu bash -c 'chown -R 1000:1000 ./* ./'
- name: Obtain Entware
if: ${{ steps.cache-restore.outputs.cache-hit != 'true' && ! matrix.k26 }}
run: |
docker run --rm -i --mount source=entware-home,target=/home/me -w /home/me --name builder builder git clone --depth 1 https://github.com/Entware/Entware.git
- name: Obtain Entware k2.6
if: ${{ steps.cache-restore.outputs.cache-hit != 'true' && matrix.k26 }}
run: |
docker run --rm -i --mount source=entware-home,target=/home/me -w /home/me --name builder builder git clone --depth 1 https://github.com/Entware/Entware.git -b k2.6
- name: Build Entware
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
docker run --rm -i --mount source=entware-home,target=/home/me -w /home/me/Entware --name builder builder make package/symlinks
docker run --rm -i --mount source=entware-home,target=/home/me -w /home/me/Entware --name builder builder cp -v configs/${{ matrix.arch }}.config .config
docker run --rm -i --mount source=entware-home,target=/home/me -w /home/me/Entware --name builder builder make -j$(nproc) toolchain/install
docker run --rm --mount source=entware-home,target=/backup_vol -v ~/entware:/backup ubuntu tar -cf /backup/entware.tar /backup_vol
- name: Save Entware to cache
if: steps.cache-restore.outputs.cache-hit != 'true'
id: cache-save
uses: actions/cache/save@v4
with:
path: ~/entware
key: entware-${{ matrix.arch }}

- name: Checkout
uses: actions/checkout@v4
with:
ref: 'entware'

- name: Prepare build
env:
VERSION: ${{ needs.prepare.outputs.version }}
RELEASE: ${{ needs.prepare.outputs.release }}
SHA: ${{ needs.prepare.outputs.sha }}
run: |
sed -i "s/PKG_REV:=.*$/PKG_REV:=$SHA/;s/PKG_VERSION:=.*$/PKG_VERSION:=$VERSION-$RELEASE-$SHA/" keenetic-pbr/Makefile
- name: Build packages
id: build
run: |
echo "src-link keeneticPbr /keeneticPbr" | docker run --rm -i --mount source=entware-home,target=/home/me -v $GITHUB_WORKSPACE:/keeneticPbr -w /home/me/Entware --name builder builder tee -a feeds.conf
docker run --rm -i --mount source=entware-home,target=/home/me -v $GITHUB_WORKSPACE:/keeneticPbr -w /home/me/Entware --name builder builder ./scripts/feeds update keeneticPbr
docker run --rm -i --mount source=entware-home,target=/home/me -v $GITHUB_WORKSPACE:/keeneticPbr -w /home/me/Entware --name builder builder ./scripts/feeds install -a -p keeneticPbr
echo "CONFIG_PACKAGE_keenetic-pbr=m" | docker run --rm -i --mount source=entware-home,target=/home/me -v $GITHUB_WORKSPACE:/keeneticPbr -w /home/me/Entware --name builder builder tee -a .config
docker run --rm -i --mount source=entware-home,target=/home/me -v $GITHUB_WORKSPACE:/keeneticPbr -w /home/me/Entware --name builder builder make package/keenetic-pbr/compile V=s
- name: Extract packages
if: steps.build.outcome == 'success'
shell: bash
env:
VERSION: ${{ needs.prepare.outputs.version }}
RELEASE: ${{ needs.prepare.outputs.release }}
SHA: ${{ needs.prepare.outputs.sha }}
run: |
mkdir output
docker run --rm --user root -i --mount source=entware-home,target=/home/me -v $(pwd):/target -w /home/me/Entware --name builder builder find ./bin -type f -name 'keenetic-pbr*.ipk' -exec cp -v {} /target/output \;
rm -rf keenetic-pbr || true
mkdir keenetic-pbr
bash -c "cp -r ./output/* keenetic-pbr"
tar -czvf keenetic-pbr-$VERSION-$RELEASE-$SHA-${{ matrix.arch }}-entware.tar.gz keenetic-pbr
- name: Upload packages
if: steps.build.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: keenetic-pbr-entware-${{ matrix.arch }}
path: ./**/keenetic-pbr*-entware.tar.gz
if-no-files-found: error

pre-release:
if: github.event_name != 'pull_request' && github.ref_name == 'main'
needs: [build-entware]
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4

- name: Upload assets
uses: slord399/action-automatic-releases@v1.0.1
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
automatic_release_tag: 'continuous'
prerelease: true
draft: true
title: 'Development build'
files: |
./**/keenetic-pbr*.ipk
./**/keenetic-pbr*.tar.gz
21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=keenetic-pbr
PKG_VERSION:=1.0.0
PKG_RELEASE:=1
PKG_REV:=$(PKG_VERSION)-$(PKG_RELEASE)

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)-$(PKG_RELEASE)

PKG_BUILD_PARALLEL:=1

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

define Package/keenetic-pbr
SECTION:=utils
CATEGORY:=Routing
DEPENDS:=+dnsmasq-full +ipset +iptables +cron +curl
DEPENDS:=+dnsmasq-full +ipset +iptables +cron
TITLE:=Tool for downloading, parsing and importing domains/ip/cidr lists into dnsmasq and ipset
URL:=https://github.com/maksimkurb/keenetic-pbr/
endef
Expand All @@ -23,14 +24,12 @@ define Package/keenetic-pbr/description
Then additional scripts from this package would be used to route traffic based on these lists.
endef

define Build/Prepare
endef
define Build/Configure
endef
define Build/Compile
GOOS=linux GOARCH=mipsle go build -ldflags "-w -s"
endef
GO_LDFLAGS += \
-X '$(XIMPORTPATH)/constant.Version=$(PKG_VERSION)' \
-w -s


GO_TARGET:=./

define Package/keenetic-pbr/install
$(INSTALL_DIR) $(1)/opt/etc/cron.daily/
Expand All @@ -39,12 +38,14 @@ define Package/keenetic-pbr/install
$(INSTALL_DIR) $(1)/opt/etc/ndm/ifstatechanged.d/
$(INSTALL_DIR) $(1)/opt/etc/keenetic-pbr/
$(INSTALL_DIR) $(1)/opt/etc/dnsmasq.d/
$(INSTALL_DIR) $(1)/opt/usr/bin/

$(INSTALL_BIN) opt/etc/cron.daily/50-keenetic-pbr-lists-update.sh $(1)/opt/etc/cron.daily/
$(INSTALL_BIN) opt/etc/ndm/fs.d/50-keenetic-pbr-disable-hwnat.sh $(1)/opt/etc/ndm/fs.d/
$(INSTALL_BIN) opt/etc/ndm/ifstatechanged.d/50-keenetic-pbr-routing.sh $(1)/opt/etc/ndm/ifstatechanged.d/
$(INSTALL_BIN) opt/etc/ndm/netfilter.d/50-keenetic-pbr-fwmarks.sh $(1)/opt/etc/ndm/netfilter.d/
$(INSTALL_BIN) opt/etc/keenetic-pbr/keenetic-pbr.conf $(1)/opt/etc/keenetic-pbr/
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/bin/keenetic-pbr $(1)/opt/usr/bin/
endef

$(eval $(call BuildPackage,keenetic-pbr))

0 comments on commit cf5ed87

Please sign in to comment.