Build and Upload #92
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Upload | |
on: | |
push: | |
tags: | |
- '^\d{4}\.\d{2}\.\d{2}-\d+$' | |
pull_request: | |
workflow_dispatch: | |
env: | |
CORE_HASH: development-v6 | |
WEB_HASH: development-v6 | |
FTL_HASH: development-v6 | |
CORE_BRANCH: development-v6 | |
WEB_BRANCH: development-v6 | |
FTL_BRANCH: development-v6 | |
# @TODO when v6 is released *_HASH should be set to commit hashes and *_BRANCH to release branches | |
jobs: | |
set-version: | |
concurrency: set-version | |
runs-on: ubuntu-latest | |
if: ${{ !contains(github.head_ref, 'gh-pages') }} | |
outputs: | |
version: ${{ steps.version.outputs.OUTPUT }} | |
steps: | |
- name: Use tag name | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
run: echo "$GITHUB_REF_NAME" > .version | |
- name: Generate version string | |
id: version | |
run: | | |
[ -f .version ] && "OUTPUT=$(cat .version)" >> $GITHUB_OUTPUT || \ | |
echo "OUTPUT=dev-$(date +%Y.%m.%d)-$(date +%H%M%S)" >> $GITHUB_OUTPUT | |
build-core: | |
concurrency: build-core-${{ github.ref_name || github.run_id }} | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.version.outputs.OUTPUT }} | |
steps: | |
- name: Checkout own repository | |
uses: actions/checkout@v4 | |
- name: Checkout pi-hole/pi-hole repository | |
uses: actions/checkout@v4 | |
with: | |
repository: pi-hole/pi-hole | |
ref: ${{ startsWith(github.ref, 'refs/tags/') && env.CORE_HASH || ( env.CORE_BRANCH || '' ) }} | |
path: ./stage | |
- name: Cache result | |
id: cache | |
uses: ./.github/actions/cache | |
with: | |
key_prefix: core- | |
patches_prefix: core | |
- name: List files (initial state) | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: ./.github/actions/list | |
with: | |
paths: . ./stage | |
- name: Apply patches | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: ./.github/actions/patch | |
with: | |
patches_prefix: core | |
- name: Save repository version infos | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: ./.github/actions/version | |
- name: Remove .git directory | |
run: rm -fr ./stage/.git | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: core | |
path: ./stage/* | |
retention-days: 1 | |
build-web: | |
concurrency: build-web-${{ github.ref_name || github.run_id }} | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.version.outputs.OUTPUT }} | |
steps: | |
- name: Checkout own repository | |
uses: actions/checkout@v4 | |
- name: Checkout pi-hole/web repository | |
uses: actions/checkout@v4 | |
with: | |
repository: pi-hole/web | |
ref: ${{ startsWith(github.ref, 'refs/tags/') && env.WEB_HASH || ( env.WEB_BRANCH || '' ) }} | |
path: ./stage | |
- name: Cache result | |
id: cache | |
uses: ./.github/actions/cache | |
with: | |
key_prefix: web- | |
patches_prefix: web | |
- name: List files (initial state) | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: ./.github/actions/list | |
with: | |
paths: . ./stage | |
- name: Apply patches | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: ./.github/actions/patch | |
with: | |
patches_prefix: web | |
- name: Save repository version infos | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: ./.github/actions/version | |
- name: Remove .git directory | |
run: rm -fr ./stage/.git | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: web | |
path: ./stage/* | |
retention-days: 1 | |
build-binary: | |
concurrency: build-binary-${{ github.ref_name || github.run_id }}-${{ matrix.arch }} | |
runs-on: ubuntu-latest | |
continue-on-error: ${{ matrix.allow-failure }} | |
outputs: | |
version: ${{ steps.version.outputs.OUTPUT }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
# - arch: aarch64 | |
# platform: linux/aarch64 | |
# allow-failure: false | |
# - arch: armv5 | |
# platform: linux/arm/v5 # EOS by Entware team | |
# allow-failure: true | |
- arch: armv7 | |
platform: linux/arm/v7 | |
allow-failure: false | |
# - arch: mipsel | |
# platform: linux/mipsel # Not supported by Pi-hole | |
# allow-failure: true | |
# - arch: mips | |
# platform: linux/mips # Not supported by Pi-hole | |
# allow-failure: true | |
# - arch: amd64 | |
# platform: linux/amd64 | |
# allow-failure: false | |
# - arch: 386 | |
# platform: linux/386 # EOS by Entware team | |
# allow-failure: false | |
steps: | |
- name: Fail this job | |
if: ${{ matrix.allow-failure && github.ref_name != 'master' && !startsWith(github.ref, 'refs/tags/') }} | |
# @TODO when v6 is released master should not be excluded here | |
run: exit 1 | |
- name: Checkout own repository | |
uses: actions/checkout@v4 | |
- name: Checkout pi-hole/FTL repository | |
uses: actions/checkout@v4 | |
with: | |
repository: pi-hole/FTL | |
ref: ${{ startsWith(github.ref, 'refs/tags/') && env.FTL_HASH || ( env.FTL_BRANCH || '' ) }} | |
path: ./stage | |
- name: Cache result | |
id: cache | |
uses: ./.github/actions/cache | |
with: | |
key_prefix: binary-${{ matrix.arch }}- | |
patches_prefix: FTL | |
files: | | |
./stage/pihole-FTL* | |
./stage/.version | |
- name: List files (initial state) | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: ./.github/actions/list | |
with: | |
paths: . ./stage | |
- name: Apply patches | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: ./.github/actions/patch | |
with: | |
patches_prefix: FTL | |
- name: Save repository version infos | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: ./.github/actions/version | |
- name: Fetch pi-hole/FTL repository infos | |
if: steps.cache.outputs.cache-hit != 'true' | |
id: version_infos | |
working-directory: ./stage | |
run: | | |
echo "GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT | |
echo "GIT_TAG=$(git describe --tags --always 2> /dev/null)" >> $GITHUB_OUTPUT | |
echo "GIT_HASH=$(git rev-parse --short=8 HEAD)" >> $GITHUB_OUTPUT | |
- name: Set up Docker Buildx | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and test FTL | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: docker/build-push-action@v5 | |
with: | |
platforms: ${{ matrix.platform }} | |
pull: true | |
push: false | |
context: ./stage | |
target: result | |
file: ./stage/.github/Dockerfile | |
outputs: | | |
type=tar,dest=stage/build.tar | |
build-args: | | |
"CI_ARCH=${{ matrix.platform }}" | |
"GIT_BRANCH=${{ steps.version_infos.outputs.GIT_BRANCH }}" | |
"GIT_TAG=${{ steps.version_infos.outputs.GIT_TAG }}" | |
- name: Extract FTL binary and generate checksum file | |
if: steps.cache.outputs.cache-hit != 'true' | |
working-directory: ./stage | |
run: | | |
tar -xf ./build.tar pihole-FTL | |
sha1sum pihole-FTL > pihole-FTL.sha1 | |
- name: List files (after build) | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: ./.github/actions/list | |
with: | |
paths: ./stage | |
- name: Remove .git directory | |
run: rm -fr ./stage/.git | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: binary-${{ matrix.arch }} | |
path: | | |
./stage/pihole-FTL* | |
./stage/.version | |
retention-days: 1 | |
build-package: | |
concurrency: build-package-${{ github.ref_name || github.run_id }}-${{ matrix.arch }} | |
needs: [set-version, build-core, build-web, build-binary] | |
runs-on: ubuntu-latest | |
continue-on-error: ${{ matrix.allow-failure }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
#- arch: aarch64 | |
# entware_arch: aarch64-3.10 | |
# allow-failure: false | |
#- arch: armv5 | |
# entware_arch: armv5-3.2 # EOS by Entware team | |
# allow-failure: true | |
#- arch: armv7 | |
# entware_arch: armv7-2.6 # EOS by Entware team | |
# allow-failure: true | |
- arch: armv7 | |
entware_arch: armv7-3.2 | |
allow-failure: false | |
#- arch: mipsel | |
# entware_arch: mipselsf-3.4 # Not supported by Pi-hole | |
# allow-failure: true | |
#- arch: mips | |
# entware_arch: mipssf-3.4 # Not supported by Pi-hole | |
# allow-failure: true | |
#- arch: amd64 | |
# entware_arch: x64-3.2 | |
# allow-failure: false | |
#- arch: 386 | |
# entware_arch: x86-2.6 # EOS by Entware team | |
# allow-failure: false | |
outputs: | |
CORE_VERSION: ${{ steps.versions.outputs.CORE }} | |
WEB_VERSION: ${{ steps.versions.outputs.WEB }} | |
FTL_VERSION: ${{ steps.versions.outputs.FTL }} | |
steps: | |
- name: Fail this job | |
if: ${{ matrix.allow-failure && github.ref_name != 'master' && !startsWith(github.ref, 'refs/tags/') }} | |
# @TODO when v6 is released master should not be excluded here | |
run: exit 1 | |
- name: Checkout own repository | |
uses: actions/checkout@v4 | |
- name: Download core artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: core | |
path: ./artifacts/core | |
- name: Download web artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: web | |
path: ./artifacts/web | |
- name: Download binary artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: binary-${{ matrix.arch }} | |
path: ./artifacts/binary | |
- name: List files (initial state) | |
uses: ./.github/actions/list | |
with: | |
paths: . ./artifacts ./artifacts/core ./artifacts/web ./artifacts/binary | |
- name: Build package | |
run: | | |
mkdir -pv ./build ./packages | |
bash ./scripts/build.sh ./build | |
bash ./scripts/ipk.sh ./build "${{ needs.set-version.outputs.version }}" ${{ matrix.entware_arch }} | |
mv -fv ./*.ipk ./packages | |
- name: Checkout Entware/ipk-html-indexer repository | |
uses: actions/checkout@v4 | |
with: | |
repository: Entware/ipk-html-indexer | |
path: ./ipk-html-indexer | |
- name: Run ipk-html-indexer | |
run: | | |
sudo ln -sv "$(readlink -f ./ipk-html-indexer/mkindex.py)" /usr/local/bin/mkindex.py | |
sudo ln -sv "$(readlink -f ./ipk-html-indexer/mkhtml.py)" /usr/local/bin/mkhtml.py | |
bash ./ipk-html-indexer/index_feed.sh -h -f ./packages | |
sed 's#href="/css#href="css#' -i ./packages/Packages.html | |
cp -frv ./ipk-html-indexer/css ./packages | |
- name: List files (after build) | |
uses: ./.github/actions/list | |
with: | |
paths: ./packages | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ipk-${{ matrix.entware_arch }} | |
path: ./packages/* | |
- name: Set versions | |
id: versions | |
run: | | |
. ./artifacts/core/.version | |
echo "CORE=$VERSION" >> $GITHUB_OUTPUT | |
. ./artifacts/web/.version | |
echo "WEB=$VERSION" >> $GITHUB_OUTPUT | |
. ./artifacts/binary/.version | |
echo "FTL=$VERSION" >> $GITHUB_OUTPUT | |
upload: | |
concurrency: upload | |
needs: [build-package] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Setup dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install rename | |
- name: Checkout own repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
sparse-checkout: /.github/* | |
sparse-checkout-cone-mode: false | |
- name: Checkout gh-pages branch | |
uses: actions/checkout@v4 | |
continue-on-error: true | |
with: | |
ref: gh-pages | |
path: ./gh-pages | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: ipk-* | |
path: ./artifacts | |
- name: Correct directory names | |
run: rename 's/ipk-//' ./artifacts/ipk-*/ | |
- name: Create changelog file | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
env: | |
CORE_VERSION: ${{ needs.build-package.outputs.CORE_VERSION }} | |
WEB_VERSION: ${{ needs.build-package.outputs.WEB_VERSION }} | |
FTL_VERSION: ${{ needs.build-package.outputs.FTL_VERSION }} | |
run: | | |
CORE_VERSION_OUT="[$CORE_VERSION](https://github.com/pi-hole/pi-hole/releases/tag/$CORE_VERSION)" | |
WEB_VERSION_OUT="[$WEB_VERSION](https://github.com/pi-hole/web/releases/tag/$WEB_VERSION)" | |
FTL_VERSION_OUT="[$FTL_VERSION](https://github.com/pi-hole/FTL/releases/tag/$FTL_VERSION)" | |
[ "$(echo "$CORE_VERSION" | cut -c1)" != "v" ] && CORE_VERSION_OUT="[$CORE_VERSION](https://github.com/pi-hole/pi-hole/commit/$CORE_VERSION)" | |
[ "$(echo "$WEB_VERSION" | cut -c1)" != "v" ] && WEB_VERSION_OUT="[$WEB_VERSION](https://github.com/pi-hole/web/commit/$WEB_VERSION)" | |
[ "$(echo "$FTL_VERSION" | cut -c1)" != "v" ] && FTL_VERSION_OUT="[$FTL_VERSION](https://github.com/pi-hole/FTL/commit/$FTL_VERSION)" | |
echo "Core version: $CORE_VERSION_OUT " >> changelog.md | |
echo "Web version: $WEB_VERSION_OUT " >> changelog.md | |
echo "FTL version: $FTL_VERSION_OUT " >> changelog.md | |
- name: Create a release | |
uses: softprops/action-gh-release@v2 | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
with: | |
files: ./artifacts/*/*.ipk | |
body_path: changelog.md | |
generate_release_notes: true | |
draft: true | |
- name: Collect new packages | |
run: | | |
mkdir -p ./gh-pages | |
find ./gh-pages -maxdepth 1 -type d -name "*-*" -exec sh -c '[ -d "./artifacts/$(basename {})" ] && rm -frv {}' \; | |
mv -v ./artifacts/* ./gh-pages | |
- name: Create directory listings | |
uses: ./.github/actions/index | |
with: | |
path: ./gh-pages | |
- name: List files | |
uses: ./.github/actions/list | |
with: | |
paths: . ./gh-pages | |
- name: Prepare for upload | |
run: | | |
find . -mindepth 1 -maxdepth 1 \( ! -name "gh-pages" -type d -exec rm -fr "{}" \; \) -o \( -type f -exec rm -f "{}" \; \) | |
cp -r ./gh-pages/. . | |
rm -fr ./gh-pages | |
git branch -m gh-pages gh-pages.old || true | |
- name: Upload packages | |
uses: JamesIves/github-pages-deploy-action@v4 | |
if: ${{ startsWith(github.ref, 'refs/tags/') || github.ref_name == 'master' }} | |
# @TODO when v6 is released builds on master should not be allowed to upload | |
with: | |
branch: gh-pages | |
folder: . | |
commit-message: Upload | |
single-commit: true | |
force: true | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: upload | |
path: | | |
./index.html | |
./*-*/* |