From fe70257697bba1eb7001676ec4628e1f6b5619ad Mon Sep 17 00:00:00 2001
From: nerdCopter <56646290+nerdCopter@users.noreply.github.com>
Date: Tue, 29 Mar 2022 17:57:53 -0500
Subject: [PATCH] 1.0.0 GitHub actions workflow (#779)
* github actions workflow
* Makefile
---
.github/workflows/build.yml | 279 ++++++++++++++++++++++++++++++++++++
Makefile | 19 ++-
2 files changed, 293 insertions(+), 5 deletions(-)
create mode 100644 .github/workflows/build.yml
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000000..4e476c406c
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,279 @@
+on:
+ push:
+ tags:
+ - '*'
+ pull_request:
+ branches:
+ - '*'
+ # repository_dispatch is a newer github-actions feature that will allow building from triggers other than code merge/PR
+ repository_dispatch:
+ types: [build]
+
+name: Build EmuFlight
+jobs:
+ build:
+ continue-on-error: false
+ timeout-minutes: 75
+ strategy:
+ max-parallel: 1
+ matrix:
+ targets: [all]
+ outputs:
+ buildtag: ${{ steps.ids.outputs.buildtag }}
+ shortsha: ${{ steps.ids.outputs.shortsha }}
+ artifact: ${{ steps.ids.outputs.artifact }}
+ version: ${{ steps.ids.outputs.version }}
+ runs-on: ubuntu-latest
+
+ steps:
+ # curl, by default, may timeout easily
+ - name: CURL Fix
+ run: function curl () { command curl --connect-timeout 30 --retry 10 "$@" ; }
+
+ # checkout with speedup #0 works, but maybe 5 safe for revisions/recompiles
+ - name: Checkout
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 5
+
+ # arm_sdk_install
+ - name: ARM_SDK_Install
+ id: arm_sdk_install
+ run: |
+ make arm_sdk_install --trace
+
+ # EmuFlight version
+ - name: Get Firmware Version
+ id: get_version
+ run: echo "VERSION=$(make version)" >> $GITHUB_ENV
+
+ # for Makefile interaction
+ - name: Get GitHub Build Number (ENV)
+ id: get_buildno
+ run: echo "GITHUBBUILDNUMBER=${{ github.run_number }}" >> $GITHUB_ENV
+
+ - name: Get Pull-Request Number
+ id: get_pullno
+ run: echo "PULL_NUMBER=$(echo "$GITHUB_REF" | awk -F / '{print $3}')" >> $GITHUB_ENV
+ if: startsWith(github.ref, 'refs/pull/')
+
+ - name: Get Revision Tag
+ if: startsWith(github.ref, 'refs/tags/')
+ id: get_revtag
+ run: echo "REVISION_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
+
+ - name: Get Short-SHA
+ run: |
+ echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
+
+ - name: Build Artifact Name
+ id: make_artifactname
+ run: |
+ if [[ "${{ github.REPOSITORY }}" == "emuflight/EmuFlight" ]] ; then
+ ARTIFACT_NAME="EmuFlight-${{ env.VERSION }}-${{ github.run_number }}"
+ else
+ ARTIFACT_NAME="EmuFlight-${{ env.VERSION }}-${{ github.ACTOR }}-${{ github.run_number }}"
+ fi
+ echo "${ARTIFACT_NAME}"
+ echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
+
+ - id: ids
+ name: Set Outputs (Variables)
+ run: |
+ echo "::set-output name=buildtag::${{ env.REVISION_TAG }}"
+ echo "::set-output name=shortsha::${{ env.SHORT_SHA }}"
+ echo "::set-output name=artifact::${{ env.ARTIFACT_NAME }}"
+ echo "::set-output name=version::${{ env.VERSION }}"
+ continue-on-error: true
+
+ # for debugging
+ - name: Show Variables
+ id: show_vars
+ run: |
+ echo "Actor: ${{ github.ACTOR }}"
+ echo "Repo: ${{ github.REPOSITORY }}"
+ echo "Build: ${{ github.run_number }}"
+ echo "Firmware: ${{ env.VERSION }}"
+ echo "Commit: ${{ github.sha }}"
+ echo "ShortSHA: ${{ env.SHORT_SHA }}"
+ echo "Tag: ${{ env.REVISION_TAG}}"
+ echo "Artifact name: ${{ env.ARTIFACT_NAME }}"
+ echo "outputs.buildtag: ${{ steps.ids.outputs.buildtag }}"
+ echo "outputs.shortsha: ${{ steps.ids.outputs.shortsha }}"
+ echo "outputs.artifact: ${{ steps.ids.outputs.artifact }}"
+ echo "outputs.artifact: ${{ steps.ids.outputs.artifact }}"
+ continue-on-error: true
+
+ # install libblocksruntime-dev
+ - name: Install libblocksruntime-dev
+ id: libblocksruntime-dev
+ run: |
+ sudo apt-get install -y libblocksruntime-dev
+
+ # checks
+ - name: UnitTests Checks
+ id: checks
+ run: |
+ make EXTRA_FLAGS=-Werror checks
+
+ # test-all
+ - name: UnitTests Test-All
+ id: test-all
+ run: |
+ make EXTRA_FLAGS=-Werror test-all
+
+ # Build HEX
+ - name: Compile Targets
+ run: |
+ make EXTRA_FLAGS=-Werror ${{ matrix.targets }}
+
+ # Upload the Builds to ZIP file with existing SHA in .hex names
+ - name: Upload Artifacts
+ uses: actions/upload-artifact@v2
+ with:
+ name: ${{ env.ARTIFACT_NAME }}
+ path: obj/*.hex
+
+ releases:
+ if: startsWith(github.ref, 'refs/tags/')
+ needs: build
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ outputs:
+ datetime: ${{ steps.ids.outputs.datetime }}
+ timeout-minutes: 10
+ runs-on: ubuntu-latest
+ continue-on-error: false
+ steps:
+ - name: Get Date
+ id: datetime
+ run: |
+ echo "::set-output name=datetime::$(date +'%Y%m%dT%H%M%S')"
+
+ # for debugging
+ - name: Show Variables
+ run: |
+ echo "Build: ${{ github.RUN_NUMBER }}"
+ echo "Commit: ${{ github.SHA }}"
+ echo "Ref: ${{ GITHUB.REF }}"
+ echo "Actor: ${{ github.ACTOR }}"
+ echo "Repo: ${{ github.REPOSITORY }}"
+ echo "outputs.buildtag: ${{ needs.build.outputs.buildtag }}"
+ echo "outputs.shortsha: ${{ needs.build.outputs.shortsha }}"
+ echo "outputs.artifact: ${{ needs.build.outputs.artifact }}"
+ echo "outputs.artifact: ${{ needs.build.outputs.version }}"
+ echo "outputs.datetime: ${{ steps.datetime.outputs.datetime }}"
+
+ continue-on-error: true
+
+ - name: Download Artifacts
+ uses: actions/download-artifact@v2
+ with:
+ name: ${{ needs.build.outputs.artifact }} #no name parameter will download all artifacts, but create separate subfolders
+ path: obj
+ continue-on-error: false
+
+ - name: List/Find Extracted Artifacts
+ run: |
+ find ./ -name "*.hex"
+
+ # Draft Dev-Unstable releases via ncipollo/release-action
+ # softprops/action-gh-release fails to release on separate repo
+ - name: Draft Release Dev-Unstable repo
+ if: contains(github.ref, 'test') || contains(github.ref, 'unstab')
+ uses: ncipollo/release-action@v1
+ with:
+ repo: dev-unstable
+ owner: emuflight
+ token: ${{ secrets.NC_PAT_EMUF }}
+ tag: "hex-${{ github.run_number }}"
+ draft: true
+ prerelease: true
+ allowUpdates: true
+ artifacts: obj/*.hex
+ artifactContentType: raw
+ name: "DEV-UNSTABLE HEX / Build ${{ github.run_number }}"
+ body: |
+ ## HEX BUILD for TESTING
+ ### Build ${{ github.run_number }}
+ ### Commit SHA: ${{ needs.build.outputs.shortsha }} (${{ github.sha }})
+ ### BuildTag: ${{ needs.build.outputs.buildtag }}
+ ### EmuFlight ${{ needs.build.outputs.version }} base plus test code
+ ### What to Test/Feedback: (Feedback in EmuFlight's Discord or GitHub Discussions)
+ Changes in this Build:
+
+
+ ```
+ [insert commit history here]
+ ```
+
+ continue-on-error: true
+
+ # Draft Dev-master releases via ncipollo/release-action
+ # softprops/action-gh-release fails to release on separate repo
+ - name: Draft Release Dev-Master repo
+ if: contains(github.ref, 'master')
+ uses: ncipollo/release-action@v1
+ with:
+ repo: dev-master
+ owner: emuflight
+ token: ${{ secrets.NC_PAT_EMUF }}
+ tag: "hex-${{ github.run_number }}"
+ draft: true
+ prerelease: true
+ allowUpdates: true
+ artifacts: obj/*.hex
+ artifactContentType: raw
+ name: "DEV-MASTER HEX / Build ${{ github.run_number }}"
+ body: |
+ ## HEX BUILD of MASTER
+ ### Build ${{ github.run_number }}
+ ### Commit SHA: ${{ needs.build.outputs.shortsha }} (${{ github.sha }})
+ ### BuildTag: ${{ needs.build.outputs.buildtag }}
+ ### EmuFlight ${{ needs.build.outputs.version }} base plus committed code
+ ### Feedback Welcome in EmuFlight's Discord or GitHub Discussions.
+ Changes in this Build:
+
+
+ ```
+ [insert commit history here]
+ ```
+
+ continue-on-error: true
+
+ # Rename .hex for true Releases on main repo
+ - name: Rename Artifacts
+ if: startsWith(github.ref, 'refs/tags/')
+ run: |
+ sudo apt -y install rename
+ cd obj
+ rename 's/_Build_.*/.hex/' *.hex
+
+ #Draft Releases on main Repo
+ # could potentially change to ncipollo/release-action as well
+ - name: Draft Release Main Repo
+ if: contains(github.ref, 'releas')
+ uses: ncipollo/release-action@v1
+ with:
+ token: ${{ secrets.GITHUB_TOKEN }}
+ draft: true
+ prerelease: true
+ allowUpdates: true
+ # tag: use the build Number, but we MUST manually change to version so that it creates a version-tag on release
+ tag: ${{ env.VERSION }}
+ artifacts: obj/*.hex
+ artifactContentType: raw
+ name: DRAFT / EmuFlight ${{ env.VERSION }} / GitHub Build ${{ github.run_number }}
+ body: |
+ ## EmuFlight ${{ env.VERSION }}
+ ### Build ${{ github.run_number }}
+ ### Commit SHA: ${{ needs.build.outputs.shortsha }} (${{ github.sha }})
+ ### BuildTag: ${{ needs.build.outputs.buildtag }}
+ Changes in this Build:
+
+
+ ```
+ [insert commit history here]
+ ```
+
+ continue-on-error: false
diff --git a/Makefile b/Makefile
index 62dd6df623..456205e781 100644
--- a/Makefile
+++ b/Makefile
@@ -56,7 +56,7 @@ RELEASE ?= no
# Things that need to be maintained as the source changes
#
-FORKNAME = betaflight
+FORKNAME = EmuFlight
# Working directories
ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
@@ -116,11 +116,19 @@ endif
include $(ROOT)/make/targets.mk
-REVISION := norevision
+BUILDDATETIME := $(shell date +'%Y%m%d%Z')
+REVISION := uncommitted_$(BUILDDATETIME)
ifeq ($(shell git diff --shortstat),)
REVISION := $(shell git log -1 --format="%h")
endif
+# build number - default for local builds
+BUILDNO := local
+# github actions build
+ifneq ($(GITHUBBUILDNUMBER),)
+BUILDNO := $(GITHUBBUILDNUMBER)
+endif
+
FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
@@ -306,10 +314,11 @@ CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
$(addprefix -I,$(INCLUDE_DIRS)) \
-I/usr/include -I/usr/include/linux
-ifeq ($(RELEASE),yes)
-TARGET_BASENAME = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET)
+#TARGET_BASENAME = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET)_$(REVISION)
+ifneq ($(BUILDNO),local)
+TARGET_BASENAME = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET)_Build_$(BUILDNO)_$(REVISION)
else
-TARGET_BASENAME = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET)_$(REVISION)
+TARGET_BASENAME = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET)_Build_$(REVISION)
endif
#