Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Wesley Gimenes <wehagy@proton.me>
  • Loading branch information
wehagy committed Jan 30, 2025
0 parents commit 7ac478f
Show file tree
Hide file tree
Showing 15 changed files with 1,308 additions and 0 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Action to build openwrt images
---
name: build openwrt images

on:
# Allows manual workflow run (must in default branch to work)
workflow_dispatch:
# Allows workflow be reusable
workflow_call:
inputs:
commit_long_sha:
required: true
type: string
# push:
# branches:
# - main
# paths:
# - 'custom-feed/**'

jobs:
build-openwrt-image:
runs-on: ubuntu-24.04

strategy:
fail-fast: false
matrix:
image:
# W
- "x86 64 generic"
- "ath79 generic tplink_archer-c7-v4"
- "mediatek filogic xiaomi_mi-router-ax3000t-ubootmod"
# P
- "ramips mt7621 totolink_x5000r"
- "mediatek filogic bananapi_bpi-r3"
# include:
# # W
# - target: "x86"
# subtarget: "64"
# profile: "generic"
# - target: "ath79"
# subtarget: "generic"
# profile: "tplink_archer-c7-v4"
# - target: "mediatek"
# subtarget: "filogic"
# profile: "xiaomi_mi-router-ax3000t-ubootmod"
# # P
# - target: "ramips"
# subtarget: "mt7621"
# profile: "totolink_x5000r"
# - target: "mediatek"
# subtarget: "filogic"
# profile: "bananapi_bpi-r3"

steps:
- name: Checkout
uses: actions/checkout@v4
#with:
# ref: ${{ inputs.commit_long_sha }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# - name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}

- name : Build
run: ./owpib ${{ matrix.image }} --install luci-app-uhttpd
# - name: Build and push
# uses: docker/build-push-action@v6
# with:
# build-args: |
# TARGET=${{ matrix.target }}
# SUBTARGET=${{ matrix.subtarget }}
# IMAGE_PROFILE=${{ matrix.profile }}
# outputs: type=local,dest=${{ matrix.profile }}

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: openwrt ${{ matrix.image }}
path: build-output/openwrt-*
44 changes: 44 additions & 0 deletions .github/workflows/compare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Action to compare if the latest version,
# if not, push commit and build
---
name: compare release

on:
# Allows manual workflow run (must in default branch to work)
workflow_dispatch:

jobs:
compare-release:
runs-on: ubuntu-24.04
permissions:
contents: write
outputs:
committed: ${{ steps.commit.outputs.committed }}
commit_long_sha: ${{ steps.commit.outputs.commit_long_sha }}

steps:
- name: Checkout repo
id: checkout-repo
uses: actions/checkout@v4

- name: compare
id: compare
run: |
sudo apt update \
&& sudo apt install -y quilt
.github/workflows/scripts/compare-release.sh
- name: commit
id: commit
if: ${{ steps.compare.outputs.sha256 != '' }}
uses: EndBug/add-and-commit@v9
with:
commit: --signoff
default_author: github_actions

build-openwrt-images:
needs: compare-release
if: ${{ needs.compare-release.outputs.committed == 'true' }}
uses: ./.github/workflows/build.yml
with:
commit_long_sha: ${{ needs.compare-release.outputs.commit_long_sha }}
55 changes: 55 additions & 0 deletions .github/workflows/scripts/compare-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

set -eux

download_file() {
local repo="${1}"
local tag="${2}"
local repo_name="${repo##*/}"
curl -sL "https://github.com/${repo}/archive/refs/tags/${tag}.tar.gz" -o "${repo_name}-${tag:1}.tar.gz"
}

calculate_sha256() {
local file="${1}"
sha256sum "${file}" | cut --delimiter=' ' --fields=1
rm "${file}"
}

REPO="netbirdio/netbird"
# Get the latest tag from the remote repository
REMOTE_TAG="$(
git ls-remote \
--refs \
--tags \
--sort='-version:refname' \
"https://github.com/${REPO}.git" \
| head --lines=1 \
| cut --delimiter='/' --fields=3
)"
REMOTE_TAG_STRIP="${REMOTE_TAG:1}"
# Get the local version from the Makefile
quilt push -a
LOCAL_TAG="$(grep -oP '(?<=PKG_VERSION:=).+' custom-feed/netbird/Makefile)"
LOCAL_TAG_STRIP="${LOCAL_TAG}"

# Check if the remote version is newer than the local version
if [[ "$(printf '%s\n%s' "${REMOTE_TAG_STRIP}" "${LOCAL_TAG_STRIP}" | sort --version-sort --check=quiet ; echo "${?}")" == 0 ]]; then
printf '%s\n' "Exiting script: No update needed."
else
printf '%s\n' "Updating: Newer version found."
download_file "$REPO" "$REMOTE_TAG"
SHA256=$(calculate_sha256 "${REPO##*/}-${REMOTE_TAG_STRIP}.tar.gz")
# Update the Makefile with the SHA256 hash and the remote version
quilt new netbird-200-update_to_"${REMOTE_TAG_STRIP}".patch
quilt add custom-feed/netbird/Makefile
sed -i "s/PKG_HASH:=.*/PKG_HASH:=${SHA256}/" custom-feed/netbird/Makefile
sed -i "s/PKG_VERSION:=.*/PKG_VERSION:=${REMOTE_TAG_STRIP}/" custom-feed/netbird/Makefile
quilt refresh

# Add the SHA256 hash to the output if in a GitHub Actions environment
[[ "${GITHUB_ACTIONS:-}" == "true" ]] && echo "sha256=${SHA256}" >> "${GITHUB_OUTPUT:-}"
fi

quilt pop -a

exit 0
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Ignore build artifacts.
build-output/*

# Ignore custom files that may contain sensitive data
# or user-specific configurations, such as local settings
# and credentials.
custom-files/*

# Include .gitkeep files in empty directories to ensure
# they are tracked by git, as git does not track empty
# directories by default.
!**/.gitkeep
Loading

0 comments on commit 7ac478f

Please sign in to comment.