Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync with upstream #32

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
# Docker on Windows.
.bashrc text eol=lf
*.sh text eol=lf
*.nix text eol=lf
110 changes: 110 additions & 0 deletions .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Build Compiler Service Container

on:
push:
tags:
- "*"
pull_request_target:
branches:
- main

jobs:
build:
# This job must never be run on a PR from outside the same repository
if: github.repository == 'moergo-sc/zmk' && (github.event.pull_request == null || github.event.pull_request.head.repo.full_name == github.repository)
runs-on: ubuntu-latest
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
env:
ECR_REPOSITORY: zmk-builder-lambda
VERSIONS_BUCKET: glove80firmwarepipelines-compilerversionsbucket44-zubaquiyjdam
UPDATE_COMPILER_VERSIONS_FUNCTION: arn:aws:lambda:us-east-1:431227615537:function:Glove80FirmwarePipelineSt-UpdateCompilerVersions2A-CNxPOHb4VSuV
REVISION_TAG: ${{ github.event.pull_request && github.event.pull_request.head.sha || github.sha }}
PR_NUMBER: ${{ github.event.number }}
steps:
- uses: actions/[email protected]
with:
repository: moergo-sc/zmk
ref: ${{ github.event.pull_request && github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::431227615537:role/GithubCompilerLambdaBuilder
aws-region: us-east-1
- name: Extract container name from branch name
shell: bash
run: |
if [ "$GITHUB_HEAD_REF" ]; then
branch_ref="$GITHUB_HEAD_REF"
type="pr"
tag="pr${PR_NUMBER}.${GITHUB_HEAD_REF}"
elif [[ "$GITHUB_REF" == refs/tags/* ]]; then
branch_ref="$GITHUB_REF"
type="tag"
tag="${GITHUB_REF#refs/tags/}"
else
echo "Not a pull request or release tag" >&2
exit 1
fi
# Replace / with . in container tag names
tag="${tag//\//.}"
echo "VERSION_BRANCH=${branch_ref}" >> $GITHUB_ENV
echo "VERSION_TYPE=${type}" >> $GITHUB_ENV
echo "VERSION_NAME=${tag}" >> $GITHUB_ENV
id: extract_name
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- uses: cachix/install-nix-action@v20
with:
nix_path: nixpkgs=channel:nixos-22.05
- uses: cachix/cachix-action@v12
with:
name: moergo-glove80-zmk-dev
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- name: Build lambda image
run: nix-build release.nix --arg revision "\"${REVISION_TAG}\"" -A lambdaImage -o lambdaImage
- name: Import OCI image into docker-daemon
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: skopeo --insecure-policy copy oci:lambdaImage docker-daemon:$REGISTRY/$ECR_REPOSITORY:$REVISION_TAG
- name: Push container image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: docker push $REGISTRY/$ECR_REPOSITORY:$REVISION_TAG
- name: Create JSON metadata to represent the built container
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
shell: bash
run: |
digest="$(docker inspect --format='{{index .RepoDigests 0}}' $REGISTRY/$ECR_REPOSITORY:$REVISION_TAG)"
digest="${digest##*@}"
api_version="$(cat lambda/api_version.txt)"
timestamp="$(date -u +"%Y%m%d.%H%M%S")"

if [ "$VERSION_TYPE" = "pr" ]; then
release_name="$VERSION_NAME.$timestamp"
else
release_name="$VERSION_NAME"
fi

jq -n '$ARGS.named' \
--arg name "$release_name" \
--arg version_name "$VERSION_NAME" \
--arg revision "$REVISION_TAG" \
--arg release_time "$timestamp" \
--arg branch "$VERSION_BRANCH" \
--arg digest "$digest" \
--arg api_version "$api_version" \
> "/tmp/$VERSION_NAME.json"
- name: Upload image metadata file to versions bucket
run: aws s3 cp "/tmp/$VERSION_NAME.json" "s3://$VERSIONS_BUCKET/images/$VERSION_NAME.json"
- name: Notify the build pipeline that the compile containers have updated
run: >-
aws lambda invoke --function-name $UPDATE_COMPILER_VERSIONS_FUNCTION
--invocation-type Event
--cli-binary-format raw-in-base64-out
/dev/null
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:

jobs:
build:
if: ${{ always() }}
if: ${{ false }}
runs-on: ubuntu-latest
container:
image: docker.io/zmkfirmware/zmk-build-arm:3.2
Expand Down Expand Up @@ -103,7 +103,7 @@ jobs:
throw new Error('Failed to build one or more configurations');
}
compile-matrix:
if: ${{ always() }}
if: ${{ false && always() }}
runs-on: ubuntu-latest
needs: [core-coverage, board-changes, nightly]
outputs:
Expand Down Expand Up @@ -143,7 +143,7 @@ jobs:
shieldArgs: JSON.stringify(shieldArgs),
}));
core-coverage:
if: ${{ needs.get-changed-files.outputs.core-changes == 'true' }}
if: ${{ false && needs.get-changed-files.outputs.core-changes == 'true' }}
runs-on: ubuntu-latest
needs: get-changed-files
outputs:
Expand Down Expand Up @@ -172,7 +172,7 @@ jobs:

return [...include, ...coreCoverage.include];
board-changes:
if: ${{ needs.get-changed-files.outputs.board-changes == 'true' }}
if: ${{ false && needs.get-changed-files.outputs.board-changes == 'true' }}
runs-on: ubuntu-latest
needs: [get-grouped-hardware, get-changed-files]
outputs:
Expand Down Expand Up @@ -256,7 +256,7 @@ jobs:
});
}))).flat();
nightly:
if: ${{ github.event_name == 'schedule' }}
if: ${{ false && github.event_name == 'schedule' }}
runs-on: ubuntu-latest
needs: get-grouped-hardware
outputs:
Expand Down Expand Up @@ -301,6 +301,7 @@ jobs:

return [...includeOnboard, ...includeInterconnect];
get-grouped-hardware:
if: ${{ false }}
runs-on: ubuntu-latest
outputs:
organized-metadata: ${{ steps.organize-metadata.outputs.result }}
Expand Down Expand Up @@ -378,7 +379,7 @@ jobs:
return JSON.stringify(grouped).replace(/\\/g,"\\\\").replace(/`/g,"\\`");
result-encoding: string
get-changed-files:
if: ${{ github.event_name != 'schedule' }}
if: ${{ false && github.event_name != 'schedule' }}
runs-on: ubuntu-latest
outputs:
changed-files: ${{ steps.changed-files.outputs.all }}
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/cleanup-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Clean up PR Compiler Service Container

on:
pull_request:
types: [closed]
branches:
- main

jobs:
build:
if: github.repository == 'moergo-sc/zmk'
runs-on: ubuntu-latest
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
env:
ECR_REPOSITORY: zmk-builder-lambda
VERSIONS_BUCKET: glove80firmwarepipelines-compilerversionsbucket44-zubaquiyjdam
UPDATE_COMPILER_VERSIONS_FUNCTION: arn:aws:lambda:us-east-1:431227615537:function:Glove80FirmwarePipelineSt-UpdateCompilerVersions2A-CNxPOHb4VSuV
PR_NUMBER: ${{ github.event.number }}
steps:
- name: Extract image tag name
shell: bash
run: |
tag="pr${PR_NUMBER}.${GITHUB_HEAD_REF}"
# Replace / with . in container tag names
tag="${tag//\//.}"
echo "VERSION_NAME=${tag}" >> $GITHUB_ENV
id: extract_name
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::431227615537:role/GithubCompilerLambdaBuilder
aws-region: us-east-1
- name: Delete the image metadata file from the versions s3 bucket
run: aws s3 rm s3://$VERSIONS_BUCKET/images/$VERSION_NAME.json
- name: Notify the build pipeline that the compile containers have updated
run: >-
aws lambda invoke --function-name $UPDATE_COMPILER_VERSIONS_FUNCTION
--invocation-type Event
--cli-binary-format raw-in-base64-out
/dev/null
62 changes: 62 additions & 0 deletions .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build Glove80 Firmware

on:
push:
paths:
- ".github/workflows/nix-build.yml"
- "default.nix"
- "app/**"
- "nix/**"
branches:
- "**"
tags:
- "**"
pull_request:
paths:
- ".github/workflows/nix-build.yml"
- "default.nix"
- "app/**"
- "nix/**"

jobs:
build:
name: Build Glove80 Firmware
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: cachix/install-nix-action@v20
with:
nix_path: nixpkgs=channel:nixos-22.05
- uses: cachix/cachix-action@v12
with:
name: moergo-glove80-zmk-dev
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
skipPush: "${{ github.repository != 'moergo-sc/zmk' }}"
- name: Build Glove80 combined firmware
run: nix-build -A glove80_combined -o combined
- name: Copy result out of nix store
run: cp combined/glove80.uf2 glove80.uf2
- name: Upload result
uses: actions/upload-artifact@v3
with:
name: glove80.uf2
path: glove80.uf2
release:
name: Create Release for Tag
if: >-
github.repository == 'moergo-sc/zmk'
&& github.event_name == 'push'
&& contains(github.ref, 'refs/tags/v')
needs: build
runs-on: ubuntu-latest
steps:
- name: Download compiled firmware artifact
uses: actions/download-artifact@v3
with:
name: glove80.uf2
- name: Create Release for Tag
uses: ncipollo/release-action@v1
with:
artifacts: "glove80.uf2"
artifactErrorsFailBuild: true
generateReleaseNotes: true
39 changes: 39 additions & 0 deletions README-NIX.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Building Zephyr™ Mechanical Keyboard (ZMK) Firmware with Nix

This extension is added by MoErgo for the Glove80 keyboard.

Nix makes setup significantly easier. With this approach `west` is not needed.
You can however still choose to build using the standard Zephyr `west` toolchain
if you wish.

# To build a target

In ZMK root directory,

nix-build -A *target* [-o *output_directory*]

For example,

nix-build -A glove80_left -o left

The `output_directory` nix creates is a symlink. If you prefer not to rely on
symlink (perhaps because you are using WSL on Windows), you can make a copy of
the resulting `uf2` file using:

cp -f $(nix-build -A *target* --no-out-link)/zmk.uf2 .

# To build Glove80

In ZMK root directory,

cp -f $(nix-build -A glove80_combined --no-out-link)/glove80.uf2 .

# Adding new targets

Edit default.nix and add an target based on zmk

An example is:

glove80_left = zmk.override {
board = "glove80_lh";
};
19 changes: 19 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ config ZMK_BLE_CLEAR_BONDS_ON_START
bool "Configuration that clears all bond information from the keyboard on startup."
default n

config ZMK_BLE_DEVICE_NAME_APPEND_SN
bool "Append the device serial number to the Bluetooth device name"
default n
select BT_DEVICE_NAME_DYNAMIC

config ZMK_BLE_DEVICE_NAME_SN_CHARS
int "Number of hexadecimal digits of serial number to append to the BT device name"
default 6
depends on ZMK_BLE_DEVICE_NAME_APPEND_SN

# HID GATT notifications sent this way are *not* picked up by Linux, and possibly others.
config BT_GATT_NOTIFY_MULTIPLE
default n
Expand Down Expand Up @@ -405,6 +415,15 @@ config ZMK_EXT_POWER
bool "Enable support to control external power output"
default y

if ZMK_EXT_POWER

config ZMK_EXT_POWER_START
bool "Enable external power output by default"
default y

#ZMK_EXT_POWER
endif

#Power Management
endmenu

Expand Down
Loading
Loading