Skip to content

Commit

Permalink
init site-ffnix
Browse files Browse the repository at this point in the history
  • Loading branch information
herbetom committed May 6, 2024
1 parent 1c1f32c commit 2581f93
Show file tree
Hide file tree
Showing 24 changed files with 1,991 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/actions/build-artifact/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Create Artifact for single-target Gluon-build"
description: "Create an artifact for a single Gluon-target which can be re-used with the build-combine action"
inputs:
gluon-path:
description: 'Path to Gluon repository containing the output directory'
required: true
hardware-target:
description: 'Hardware target to create the artifact for'
required: true
runs:
using: 'composite'
steps:
- run: mkdir -p "$GITHUB_WORKSPACE/build-artifact-workdir"
shell: bash
- run: tar -cJf "$GITHUB_WORKSPACE/build-artifact-workdir/output.tar.xz" -C ${{ inputs.gluon-path }}/output images packages debug
shell: bash
- uses: actions/upload-artifact@v4
with:
name: ${{ inputs.hardware-target }}
path: build-artifact-workdir
compression-level: 0
- run: rm -rf "$GITHUB_WORKSPACE/build-artifact-workdir"
shell: bash
29 changes: 29 additions & 0 deletions .github/actions/build-combine/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Combine artifacts"
description: "Combine artifacts built by build-artifact"
inputs:
artifact-dir:
description: 'Path to downloaded artifacts'
required: true
output-dir:
description: 'Path to store the combined output directory into'
required: true
keep-packed:
description: 'Instead of extracting and combining the output folders, keep the archive packed (Default: 0)'
default: 0
delete-combined:
description: 'Delete artifact downloads which were combined (Default: 1)'
default: 1
targets:
description: 'JSON Array containing all names of targets build-jobs were created for'
required: true
runs:
using: 'composite'
steps:
- run: bash $GITHUB_ACTION_PATH/combine-build.sh
shell: bash
env:
ACTION_ARTIFACT_DIR: ${{ inputs.artifact-dir }}
ACTION_DELETE_COMBINED: ${{ inputs.delete-combined }}
ACTION_KEEP_PACKED: ${{ inputs.keep-packed }}
ACTION_OUTPUT_DIR: ${{ inputs.output-dir }}
ACTION_TARGETS: ${{ inputs.targets }}
68 changes: 68 additions & 0 deletions .github/actions/build-combine/combine-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

set -euxo pipefail

# Generate space-separated list of targets to combine
TARGET_LIST=""
if [ -n "$ACTION_TARGETS" ]; then
TARGET_LIST=$(echo "$ACTION_TARGETS" | jq -r '.[]' | paste -sd ' ')
fi

# Read target names to list
ARTIFACT_NAMES=""
for filename in $ACTION_ARTIFACT_DIR/*/ ; do
artifact_folder_name="$(basename $filename)"
echo "Target artifact: ${artifact_folder_name} (Full: ${filename})"

ARTIFACT_NAMES="${ARTIFACT_NAMES} $artifact_folder_name"
done

# Combine artifacts
ARTIFACT_OUT_DIR="$RUNNER_TEMP/output"
EXTRACT_TEMP_DIR="$RUNNER_TEMP/extract"

mkdir -p "$ARTIFACT_OUT_DIR"
for artifact_target in $ARTIFACT_NAMES ; do
# Check if artifact in list. Only delete otherwise.
if [ -n "$TARGET_LIST" ] && [[ "$TARGET_LIST" =~ "$artifact_target" ]]; then
echo "Combining ${artifact_target}"

EXTRACT_TEMP_DIR_TARGET="${EXTRACT_TEMP_DIR}/${artifact_target}"
ARTIFACT_SRC_DIR_TARGET="${ACTION_ARTIFACT_DIR}/${artifact_target}"

if [[ "$ACTION_KEEP_PACKED" != "1" ]]; then
# Create Temporary extraction directory
mkdir -p "${EXTRACT_TEMP_DIR_TARGET}"

# Unpack archive
tar xf "${ARTIFACT_SRC_DIR_TARGET}/output.tar.xz" -C "${EXTRACT_TEMP_DIR_TARGET}"

# Combine targets
rsync -a ${EXTRACT_TEMP_DIR_TARGET}/* "$ARTIFACT_OUT_DIR"

# Remove temporary extraction directory
rm -rf "${EXTRACT_TEMP_DIR_TARGET}"
else
# Copy and rename archive
cp "${ARTIFACT_SRC_DIR_TARGET}/output.tar.xz" "${ARTIFACT_OUT_DIR}/${artifact_target}.tar.xz"
fi

# Delete artifacts if enabled
if [ "${ACTION_DELETE_COMBINED}" -eq "1" ]; then
rm -rf "${ARTIFACT_SRC_DIR_TARGET}"
fi
else
echo "Skipping ${artifact_target}"
fi
done

tree "$ARTIFACT_OUT_DIR"

# Move combined artifacts to artifact directory
mkdir -p "$ACTION_OUTPUT_DIR"
mv $ARTIFACT_OUT_DIR/* "$ACTION_OUTPUT_DIR"

tree "$ACTION_OUTPUT_DIR"

# Remove temporary directory
rm -rf "$EXTRACT_TEMP_DIR"
32 changes: 32 additions & 0 deletions .github/build-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"gluon": {
"repository": "freifunk-gluon/gluon",
"branch": "master",
"commit": "5388eb1542d280cafb5d0662a41ba63a85e88f95"
},
"container": {
"version": "master"
},
"build": {
"targets": [
"armsr-armv7",
"armsr-armv8",
"ath79-generic",
"ath79-nand",
"ipq40xx-generic",
"lantiq-xrx200",
"lantiq-xway",
"mediatek-filogic",
"mediatek-mt7622",
"mpc85xx-p1010",
"mpc85xx-p1020",
"ramips-mt7620",
"ramips-mt7621",
"ramips-mt76x8",
"rockchip-armv8",
"x86-64",
"x86-generic",
"x86-geode"
]
}
}
198 changes: 198 additions & 0 deletions .github/build-meta.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
#!/bin/bash

set -euxo pipefail

SCRIPT_DIR="$(dirname "$0")"

# Get Git short hash for repo at $SCRIPT_DIR
GIT_SHORT_HASH="$(git -C "$SCRIPT_DIR" rev-parse --short HEAD)"

# Get date of last Git commit for repo at $SCRIPT_DIR
GIT_COMMIT_DATE="$(git -C "$SCRIPT_DIR" log -1 --format=%cd --date=format:'%Y%m%d')"

# Build BROKEN by default. Disable for release builds.
BROKEN="1"

# Don't deploy by default. Enable for release and nightly builds.
DEPLOY="0"

# Don't release by default. Enable for tags.
CREATE_RELEASE="0"

# Create pre-releases by default. Disable for release builds.
PRE_RELEASE="1"

# Don't link release by default. Enable for nightly.
LINK_RELEASE="0"

# Target whitelist
if [ -n "$WORKFLOW_DISPATCH_TARGETS" ]; then
# Get targets from dispatch event
TARGET_WHITELIST="$WORKFLOW_DISPATCH_TARGETS"
else
# Get targets from build-info.json
TARGET_WHITELIST="$(jq -r -e '.build.targets | join(" ")' "$SCRIPT_DIR/build-info.json")"
fi

# Release Branch regex
RELEASE_BRANCH_RE="^v20[0-9]{2}\.[0-9]\.x$"
# Regex for nightly firmware tag
NIGHTLY_TAG_RE="^v[2-9].[0-9].x-[0-9]{8}$"
# Regex for custom nightly firmware tag
CUSTOM_NIGHTLY_TAG_RE="^v[2-9].[0-9].x-[0-9]{8}"
# Regex for release firmware tag
RELEASE_TAG_RE="^v[2-9].[0-9].[0-9]$"

# Get Gluon version information
if [ -n "$WORKFLOW_DISPATCH_REPOSITORY" ] && [ -n "$WORKFLOW_DISPATCH_REFERENCE" ]; then
# Get Gluon version information from dispatch event
GLUON_REPOSITORY="$WORKFLOW_DISPATCH_REPOSITORY"
GLUON_COMMIT="$WORKFLOW_DISPATCH_REFERENCE"
else
# Get Gluon version information from build-info.json
GLUON_REPOSITORY="$(jq -r -e .gluon.repository "$SCRIPT_DIR/build-info.json")"
GLUON_COMMIT="$(jq -r -e .gluon.commit "$SCRIPT_DIR/build-info.json")"
fi

# Get Container version information
CONTAINER_VERSION="$(jq -r -e .container.version "$SCRIPT_DIR/build-info.json")"

# Get Default Release version from site.mk
DEFAULT_RELEASE_VERSION="$(make --no-print-directory -C "$SCRIPT_DIR/.." -f ci-build.mk version)"
DEFAULT_RELEASE_VERSION="$DEFAULT_RELEASE_VERSION-$GIT_SHORT_HASH"

# Create site-version from site.mk
SITE_VERSION="$(make --no-print-directory -C "$SCRIPT_DIR/.." -f ci-build.mk site-version)"
SITE_VERSION="$SITE_VERSION-ffnix-$GIT_COMMIT_DATE-$GIT_SHORT_HASH"

# Enable Manifest generation conditionally
MANIFEST_STABLE="0"
MANIFEST_BETA="0"
MANIFEST_EXPERIMENTAL="0"
MANIFEST_NIGHTLY="0"

# Only Sign manifest on release builds
SIGN_MANIFEST="0"

echo "GitHub Event-Name: $GITHUB_EVENT_NAME"
echo "GitHub Ref-Type: $GITHUB_REF_TYPE"
echo "GitHub Ref-Name: $GITHUB_REF_NAME"

if [ "$GITHUB_EVENT_NAME" = "push" ] && [ "$GITHUB_REF_TYPE" = "branch" ]; then
if [ "$GITHUB_REF_NAME" = "main" ]; then
# Push to main - autoupdater Branch is nightly and enabled
AUTOUPDATER_ENABLED="1"
AUTOUPDATER_BRANCH="nightly"

MANIFEST_NIGHTLY="1"
elif [[ "$GITHUB_REF_NAME" =~ $RELEASE_BRANCH_RE ]]; then
# Push to release branch - autoupdater Branch is stable and enabled
AUTOUPDATER_ENABLED="1"
AUTOUPDATER_BRANCH="stable"

MANIFEST_STABLE="1"
MANIFEST_BETA="1"
MANIFEST_EXPERIMENTAL="1"
else
# Push to unknown branch - Disable autoupdater
AUTOUPDATER_ENABLED="0"
AUTOUPDATER_BRANCH="nightly"
fi
elif [ "$GITHUB_EVENT_NAME" = "push" ] && [ "$GITHUB_REF_TYPE" = "tag" ]; then
if [[ "$GITHUB_REF_NAME" =~ $NIGHTLY_TAG_RE ]]; then
# Nightly release - autoupdater Branch is nightly and enabled
AUTOUPDATER_ENABLED="1"
AUTOUPDATER_BRANCH="nightly"

MANIFEST_NIGHTLY="1"
SIGN_MANIFEST="1"

RELEASE_VERSION="$GITHUB_REF_NAME"
# remove v prefix
RELEASE_VERSION="${RELEASE_VERSION#"v"}"
DEPLOY="1"
LINK_RELEASE="1"
elif [[ "$GITHUB_REF_NAME" =~ $RELEASE_TAG_RE ]]; then
# Stable release - autoupdater Branch is stable and enabled
AUTOUPDATER_ENABLED="1"
AUTOUPDATER_BRANCH="stable"

MANIFEST_STABLE="1"
MANIFEST_BETA="1"
MANIFEST_EXPERIMENTAL="1"
SIGN_MANIFEST="1"

RELEASE_VERSION="$GITHUB_REF_NAME"
# remove v prefix
RELEASE_VERSION="${RELEASE_VERSION#"v"}"
BROKEN="0"
DEPLOY="1"
PRE_RELEASE="0"
else
# Unknown release - Disable autoupdater
AUTOUPDATER_ENABLED="0"
AUTOUPDATER_BRANCH="nightly"

if [[ "$GITHUB_REF_NAME" =~ $CUSTOM_NIGHTLY_TAG_RE ]]; then
# Custom nightly tag

RELEASE_VERSION="$GITHUB_REF_NAME"
# remove v prefix
RELEASE_VERSION="${RELEASE_VERSION#"v"}"
fi
fi

CREATE_RELEASE="1"
elif [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ] || [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
# Workflow Dispatch - autoupdater Branch is nightly and disabled
AUTOUPDATER_ENABLED="0"
AUTOUPDATER_BRANCH="nightly"
else
echo "Unknown ref type $GITHUB_REF_TYPE"
exit 1
fi

# Ensure we don't {sign,deploy,release} on pull requests
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
DEPLOY="0"
CREATE_RELEASE="0"
SIGN_MANIFEST="0"
fi

# Determine Version to use
RELEASE_VERSION="${RELEASE_VERSION:-$DEFAULT_RELEASE_VERSION}"

# Write build-meta to dedicated file before appending GITHUB_OUTPUT.
# This way, we can create an artifact for our build-meta to eventually upload to a release.
BUILD_META_TMP_DIR="$(mktemp -d)"
BUILD_META_OUTPUT="$BUILD_META_TMP_DIR/build-meta.txt"

# shellcheck disable=SC2129
# Not the nicest way to do this, but it works.
echo "build-meta-output=$BUILD_META_TMP_DIR" >> "$BUILD_META_OUTPUT"
echo "container-version=$CONTAINER_VERSION" >> "$BUILD_META_OUTPUT"
echo "gluon-repository=$GLUON_REPOSITORY" >> "$BUILD_META_OUTPUT"
echo "gluon-commit=$GLUON_COMMIT" >> "$BUILD_META_OUTPUT"
echo "site-version=$SITE_VERSION" >> "$BUILD_META_OUTPUT"
echo "release-version=$RELEASE_VERSION" >> "$BUILD_META_OUTPUT"
echo "autoupdater-enabled=$AUTOUPDATER_ENABLED" >> "$BUILD_META_OUTPUT"
echo "autoupdater-branch=$AUTOUPDATER_BRANCH" >> "$BUILD_META_OUTPUT"
echo "broken=$BROKEN" >> "$BUILD_META_OUTPUT"
echo "manifest-stable=$MANIFEST_STABLE" >> "$BUILD_META_OUTPUT"
echo "manifest-beta=$MANIFEST_BETA" >> "$BUILD_META_OUTPUT"
echo "manifest-experimental=$MANIFEST_EXPERIMENTAL" >> "$BUILD_META_OUTPUT"
echo "manifest-nightly=$MANIFEST_NIGHTLY" >> "$BUILD_META_OUTPUT"
echo "sign-manifest=$SIGN_MANIFEST" >> "$BUILD_META_OUTPUT"
echo "deploy=$DEPLOY" >> "$BUILD_META_OUTPUT"
echo "link-release=$LINK_RELEASE" >> "$BUILD_META_OUTPUT"
echo "create-release=$CREATE_RELEASE" >> "$BUILD_META_OUTPUT"
echo "pre-release=$PRE_RELEASE" >> "$BUILD_META_OUTPUT"
echo "target-whitelist=$TARGET_WHITELIST" >> "$BUILD_META_OUTPUT"

# Copy over to GITHUB_OUTPUT
cat "$BUILD_META_OUTPUT" >> "$GITHUB_OUTPUT"

# Display Output so we can conveniently check it from CI log viewer
cat "$GITHUB_OUTPUT"

exit 0
33 changes: 33 additions & 0 deletions .github/bump-gluon-commit-message.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -e

repo_path="$1"
old_commit="$2"
new_commit="$3"

# Check if all arguments are set, print usage otherwise
if [ -z "$repo_path" ] || [ -z "$old_commit" ] || [ -z "$new_commit" ]; then
echo "Usage: bump-gluon-commit-message.sh <repo-path> <old-commit> <new-commit>"
exit 1
fi

# Get short-ref of commits
old_commit_short="$(git -C "$repo_path" rev-parse --short "$old_commit")"
new_commit_short="$(git -C "$repo_path" rev-parse --short "$new_commit")"

# Get commit date of new commit (YYYY-MM-DD)
new_commit_date="$(git -C "$repo_path" show -s --format=%cd --date=short "$new_commit")"

# Get Git log of commit delta
commit_log="$(git -C "$repo_path" log --oneline --no-decorate "$old_commit".."$new_commit")"

cat <<EOF
build-info: update Gluon to $new_commit_date
Update Gluon from $old_commit_short to $new_commit_short.
~~~
$commit_log
~~~
EOF
Loading

0 comments on commit 2581f93

Please sign in to comment.