Skip to content

Commit

Permalink
feat: build ipk via Actions
Browse files Browse the repository at this point in the history
Signed-off-by: Tianling Shen <[email protected]>
  • Loading branch information
1715173329 committed Sep 16, 2021
1 parent ccc100f commit 9f4fd20
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/build-ipk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-only
#
# Copyright (C) 2021 Tianling Shen <[email protected]>

export PKG_SOURCE_DATE_EPOCH="$(date "+%s")"

PKG_DIR="$(realpath $PWD/../)"

function get_mk_value() {
awk -F "$1:=" '{print $2}' "$PKG_DIR/Makefile" | xargs
}

PKG_NAME="$(get_mk_value "PKG_NAME")"
if [ "$RELEASE_TYPE" == "release" ]; then
PKG_VERSION="$(get_mk_value "PKG_VERSION")-$(get_mk_value "PKG_RELEASE")"
else
PKG_VERSION="dev-$(date --date="@$PKG_SOURCE_DATE_EPOCH" "+%Y%m%d")-$(git rev-parse --short HEAD)"
fi

TEMP_DIR="$(mktemp -d -p $PWD)"
TEMP_PKG_DIR="$TEMP_DIR/$(get_mk_value "PKG_NAME")"
mkdir -p "$TEMP_PKG_DIR/CONTROL/"
mkdir -p "$TEMP_PKG_DIR/usr/lib/lua/luci/"

cp -fpR "$PKG_DIR/luasrc"/* "$TEMP_PKG_DIR/usr/lib/lua/luci/"
cp -fpR "$PKG_DIR/root"/* "$TEMP_PKG_DIR/"

echo -e "/etc/config/unblockneteasemusic" > "$TEMP_PKG_DIR/CONTROL/conffiles"

cat > "$TEMP_PKG_DIR/CONTROL/control" <<-EOF
Package: $PKG_NAME
Version: $PKG_VERSION
Depends: libc, $(get_mk_value "LUCI_DEPENDS" | tr " +" ", " | xargs)
Source: https://github.com/immortalwrt/luci-app-unblockneteasemusic
SourceName: $PKG_NAME
Section: luci
SourceDateEpoch: $PKG_SOURCE_DATE_EPOCH
Maintainer: Tianling Shen <[email protected]>
Architecture: all
Installed-Size: TO-BE-FILLED-BY-IPKG-BUILD
Description: LuCI support for UnblockNeteaseMusic
EOF

echo -e '#!/bin/sh
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
[ -s ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0
. ${IPKG_INSTROOT}/lib/functions.sh
default_postinst $0 $@' > "$TEMP_PKG_DIR/CONTROL/postinst"
chmod 0755 "$TEMP_PKG_DIR/CONTROL/postinst"

echo -e "[ -n "\${IPKG_INSTROOT}" ] || {
(. /etc/uci-defaults/$PKG_NAME) && rm -f /etc/uci-defaults/$PKG_NAME
rm -f /tmp/luci-indexcache
rm -rf /tmp/luci-modulecache/
exit 0
}" > "$TEMP_PKG_DIR/CONTROL/postinst-pkg"
chmod 0755 "$TEMP_PKG_DIR/CONTROL/postinst-pkg"

echo -e '#!/bin/sh
[ -s ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0
. ${IPKG_INSTROOT}/lib/functions.sh
default_prerm $0 $@' > "$TEMP_PKG_DIR/CONTROL/prerm"
chmod 0755 "$TEMP_PKG_DIR/CONTROL/prerm"

curl -fsSL "https://raw.githubusercontent.com/openwrt/openwrt/master/scripts/ipkg-build" -o "$TEMP_DIR/ipkg-build"
chmod 0755 "$TEMP_DIR/ipkg-build"
"$TEMP_DIR/ipkg-build" -m "/:root:root:0755" "$TEMP_PKG_DIR" "$TEMP_DIR"

mv "$TEMP_DIR/${PKG_NAME}_${PKG_VERSION}_all.ipk" "$PWD"
rm -rf "$TEMP_DIR"
64 changes: 64 additions & 0 deletions .github/workflows/build-ipk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build ipk for luci-app-unblockneteasemusic

on:
push:
branches:
- 'master'
paths:
- 'luasrc/**'
- 'root/**'
- 'Makefile'
- '.github/workflows/*.yml'

pull_request:
types:
- opened
- synchronize
- reopened
paths:
- 'luasrc/**'
- 'root/**'
- 'Makefile'
- '.github/workflows/*.yml'

release:
types:
- published

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout source tree
uses: actions/checkout@v2

- name: Setup dependencies
run: |
sudo -E apt -qq update
sudo -E apt -qq install curl fakeroot tar
- name: Build ipk file
env:
RELEASE_TYPE: ${{ github.event_name }}
run: |
pushd .github
fakeroot bash build-ipk.sh
echo "ASSET_NAME=$(ls *.ipk)" >> $GITHUB_ENV
popd
- name: Publishing to GitHub Artifacts
uses: actions/upload-artifact@v2
if: github.event_name != 'release'
with:
name: ${{ env.ASSET_NAME }}
path: .github/*.ipk

- name: Publishing to GitHub Releases
uses: svenstaro/upload-release-action@v2
if: github.event_name == 'release'
with:
repo_token: ${{ github.token }}
file: .github/*.ipk
tag: ${{ github.ref }}
file_glob: true

0 comments on commit 9f4fd20

Please sign in to comment.