|
| 1 | +on: |
| 2 | + push: |
| 3 | + tags: |
| 4 | + - '*' |
| 5 | + pull_request: |
| 6 | + branches: |
| 7 | + - '*' |
| 8 | + # repository_dispatch is a newer github-actions feature that will allow building from triggers other than code merge/PR |
| 9 | + repository_dispatch: |
| 10 | + types: [build] |
| 11 | + |
| 12 | +name: Build EmuFlight |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + continue-on-error: false |
| 16 | + timeout-minutes: 75 |
| 17 | + strategy: |
| 18 | + max-parallel: 1 |
| 19 | + matrix: |
| 20 | + targets: [all] |
| 21 | + outputs: |
| 22 | + buildtag: ${{ steps.ids.outputs.buildtag }} |
| 23 | + shortsha: ${{ steps.ids.outputs.shortsha }} |
| 24 | + artifact: ${{ steps.ids.outputs.artifact }} |
| 25 | + version: ${{ steps.ids.outputs.version }} |
| 26 | + runs-on: ubuntu-latest |
| 27 | + |
| 28 | + steps: |
| 29 | + # curl, by default, may timeout easily |
| 30 | + - name: CURL Fix |
| 31 | + run: function curl () { command curl --connect-timeout 30 --retry 10 "$@" ; } |
| 32 | + |
| 33 | + # checkout with speedup #0 works, but maybe 5 safe for revisions/recompiles |
| 34 | + - name: Checkout |
| 35 | + uses: actions/checkout@v2 |
| 36 | + with: |
| 37 | + fetch-depth: 5 |
| 38 | + |
| 39 | + # arm_sdk_install |
| 40 | + - name: ARM_SDK_Install |
| 41 | + id: arm_sdk_install |
| 42 | + run: | |
| 43 | + make arm_sdk_install --trace |
| 44 | +
|
| 45 | + # EmuFlight version |
| 46 | + - name: Get Firmware Version |
| 47 | + id: get_version |
| 48 | + run: echo "VERSION=$(make version)" >> $GITHUB_ENV |
| 49 | + |
| 50 | + # for Makefile interaction |
| 51 | + - name: Get GitHub Build Number (ENV) |
| 52 | + id: get_buildno |
| 53 | + run: echo "GITHUBBUILDNUMBER=${{ github.run_number }}" >> $GITHUB_ENV |
| 54 | + |
| 55 | + - name: Get Pull-Request Number |
| 56 | + id: get_pullno |
| 57 | + run: echo "PULL_NUMBER=$(echo "$GITHUB_REF" | awk -F / '{print $3}')" >> $GITHUB_ENV |
| 58 | + if: startsWith(github.ref, 'refs/pull/') |
| 59 | + |
| 60 | + - name: Get Revision Tag |
| 61 | + if: startsWith(github.ref, 'refs/tags/') |
| 62 | + id: get_revtag |
| 63 | + run: echo "REVISION_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV |
| 64 | + |
| 65 | + - name: Get Short-SHA |
| 66 | + run: | |
| 67 | + echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV |
| 68 | +
|
| 69 | + - name: Build Artifact Name |
| 70 | + id: make_artifactname |
| 71 | + run: | |
| 72 | + if [[ "${{ github.REPOSITORY }}" == "emuflight/EmuFlight" ]] ; then |
| 73 | + ARTIFACT_NAME="EmuFlight-${{ env.VERSION }}-${{ github.run_number }}" |
| 74 | + else |
| 75 | + ARTIFACT_NAME="EmuFlight-${{ env.VERSION }}-${{ github.ACTOR }}-${{ github.run_number }}" |
| 76 | + fi |
| 77 | + echo "${ARTIFACT_NAME}" |
| 78 | + echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV |
| 79 | +
|
| 80 | + - id: ids |
| 81 | + name: Set Outputs (Variables) |
| 82 | + run: | |
| 83 | + echo "::set-output name=buildtag::${{ env.REVISION_TAG }}" |
| 84 | + echo "::set-output name=shortsha::${{ env.SHORT_SHA }}" |
| 85 | + echo "::set-output name=artifact::${{ env.ARTIFACT_NAME }}" |
| 86 | + echo "::set-output name=version::${{ env.VERSION }}" |
| 87 | + continue-on-error: true |
| 88 | + |
| 89 | + # for debugging |
| 90 | + - name: Show Variables |
| 91 | + id: show_vars |
| 92 | + run: | |
| 93 | + echo "Actor: ${{ github.ACTOR }}" |
| 94 | + echo "Repo: ${{ github.REPOSITORY }}" |
| 95 | + echo "Build: ${{ github.run_number }}" |
| 96 | + echo "Firmware: ${{ env.VERSION }}" |
| 97 | + echo "Commit: ${{ github.sha }}" |
| 98 | + echo "ShortSHA: ${{ env.SHORT_SHA }}" |
| 99 | + echo "Tag: ${{ env.REVISION_TAG}}" |
| 100 | + echo "Artifact name: ${{ env.ARTIFACT_NAME }}" |
| 101 | + echo "outputs.buildtag: ${{ steps.ids.outputs.buildtag }}" |
| 102 | + echo "outputs.shortsha: ${{ steps.ids.outputs.shortsha }}" |
| 103 | + echo "outputs.artifact: ${{ steps.ids.outputs.artifact }}" |
| 104 | + echo "outputs.artifact: ${{ steps.ids.outputs.artifact }}" |
| 105 | + continue-on-error: true |
| 106 | + |
| 107 | + # install libblocksruntime-dev |
| 108 | + - name: Install libblocksruntime-dev |
| 109 | + id: libblocksruntime-dev |
| 110 | + run: | |
| 111 | + sudo apt-get install -y libblocksruntime-dev |
| 112 | +
|
| 113 | + # checks |
| 114 | + - name: UnitTests Checks |
| 115 | + id: checks |
| 116 | + run: | |
| 117 | + make EXTRA_FLAGS=-Werror checks |
| 118 | +
|
| 119 | + # test-all |
| 120 | + - name: UnitTests Test-All |
| 121 | + id: test-all |
| 122 | + run: | |
| 123 | + make EXTRA_FLAGS=-Werror test-all |
| 124 | +
|
| 125 | + # Build HEX |
| 126 | + - name: Compile Targets |
| 127 | + run: | |
| 128 | + make EXTRA_FLAGS=-Werror ${{ matrix.targets }} |
| 129 | +
|
| 130 | + # Upload the Builds to ZIP file with existing SHA in .hex names |
| 131 | + - name: Upload Artifacts |
| 132 | + uses: actions/upload-artifact@v2 |
| 133 | + with: |
| 134 | + name: ${{ env.ARTIFACT_NAME }} |
| 135 | + path: obj/*.hex |
| 136 | + |
| 137 | + releases: |
| 138 | + if: startsWith(github.ref, 'refs/tags/') |
| 139 | + needs: build |
| 140 | + env: |
| 141 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 142 | + outputs: |
| 143 | + datetime: ${{ steps.ids.outputs.datetime }} |
| 144 | + timeout-minutes: 10 |
| 145 | + runs-on: ubuntu-latest |
| 146 | + continue-on-error: false |
| 147 | + steps: |
| 148 | + - name: Get Date |
| 149 | + id: datetime |
| 150 | + run: | |
| 151 | + echo "::set-output name=datetime::$(date +'%Y%m%dT%H%M%S')" |
| 152 | +
|
| 153 | + # for debugging |
| 154 | + - name: Show Variables |
| 155 | + run: | |
| 156 | + echo "Build: ${{ github.RUN_NUMBER }}" |
| 157 | + echo "Commit: ${{ github.SHA }}" |
| 158 | + echo "Ref: ${{ GITHUB.REF }}" |
| 159 | + echo "Actor: ${{ github.ACTOR }}" |
| 160 | + echo "Repo: ${{ github.REPOSITORY }}" |
| 161 | + echo "outputs.buildtag: ${{ needs.build.outputs.buildtag }}" |
| 162 | + echo "outputs.shortsha: ${{ needs.build.outputs.shortsha }}" |
| 163 | + echo "outputs.artifact: ${{ needs.build.outputs.artifact }}" |
| 164 | + echo "outputs.artifact: ${{ needs.build.outputs.version }}" |
| 165 | + echo "outputs.datetime: ${{ steps.datetime.outputs.datetime }}" |
| 166 | +
|
| 167 | + continue-on-error: true |
| 168 | + |
| 169 | + - name: Download Artifacts |
| 170 | + uses: actions/download-artifact@v2 |
| 171 | + with: |
| 172 | + name: ${{ needs.build.outputs.artifact }} #no name parameter will download all artifacts, but create separate subfolders |
| 173 | + path: obj |
| 174 | + continue-on-error: false |
| 175 | + |
| 176 | + - name: List/Find Extracted Artifacts |
| 177 | + run: | |
| 178 | + find ./ -name "*.hex" |
| 179 | +
|
| 180 | + # Draft Dev-Unstable releases via ncipollo/release-action |
| 181 | + # softprops/action-gh-release fails to release on separate repo |
| 182 | + - name: Draft Release Dev-Unstable repo |
| 183 | + if: contains(github.ref, 'test') || contains(github.ref, 'unstab') |
| 184 | + uses: ncipollo/release-action@v1 |
| 185 | + with: |
| 186 | + repo: dev-unstable |
| 187 | + owner: emuflight |
| 188 | + token: ${{ secrets.NC_PAT_EMUF }} |
| 189 | + tag: "hex-${{ github.run_number }}" |
| 190 | + draft: true |
| 191 | + prerelease: true |
| 192 | + allowUpdates: true |
| 193 | + artifacts: obj/*.hex |
| 194 | + artifactContentType: raw |
| 195 | + name: "DEV-UNSTABLE HEX / Build ${{ github.run_number }}" |
| 196 | + body: | |
| 197 | + ## HEX BUILD for TESTING |
| 198 | + ### Build ${{ github.run_number }} |
| 199 | + ### Commit SHA: ${{ needs.build.outputs.shortsha }} (${{ github.sha }}) |
| 200 | + ### BuildTag: ${{ needs.build.outputs.buildtag }} |
| 201 | + ### EmuFlight ${{ needs.build.outputs.version }} base plus test code |
| 202 | + ### What to Test/Feedback: (Feedback in EmuFlight's Discord or GitHub Discussions) |
| 203 | + <details><summary>Changes in this Build:</summary> |
| 204 | + <!-- require single blank line below --> |
| 205 | +
|
| 206 | + ``` |
| 207 | + [insert commit history here] |
| 208 | + ``` |
| 209 | + </details> |
| 210 | + continue-on-error: true |
| 211 | + |
| 212 | + # Draft Dev-master releases via ncipollo/release-action |
| 213 | + # softprops/action-gh-release fails to release on separate repo |
| 214 | + - name: Draft Release Dev-Master repo |
| 215 | + if: contains(github.ref, 'master') |
| 216 | + uses: ncipollo/release-action@v1 |
| 217 | + with: |
| 218 | + repo: dev-master |
| 219 | + owner: emuflight |
| 220 | + token: ${{ secrets.NC_PAT_EMUF }} |
| 221 | + tag: "hex-${{ github.run_number }}" |
| 222 | + draft: true |
| 223 | + prerelease: true |
| 224 | + allowUpdates: true |
| 225 | + artifacts: obj/*.hex |
| 226 | + artifactContentType: raw |
| 227 | + name: "DEV-MASTER HEX / Build ${{ github.run_number }}" |
| 228 | + body: | |
| 229 | + ## HEX BUILD of MASTER |
| 230 | + ### Build ${{ github.run_number }} |
| 231 | + ### Commit SHA: ${{ needs.build.outputs.shortsha }} (${{ github.sha }}) |
| 232 | + ### BuildTag: ${{ needs.build.outputs.buildtag }} |
| 233 | + ### EmuFlight ${{ needs.build.outputs.version }} base plus committed code |
| 234 | + ### Feedback Welcome in EmuFlight's Discord or GitHub Discussions. |
| 235 | + <details><summary>Changes in this Build:</summary> |
| 236 | + <!-- require single blank line below --> |
| 237 | +
|
| 238 | + ``` |
| 239 | + [insert commit history here] |
| 240 | + ``` |
| 241 | + </details> |
| 242 | + continue-on-error: true |
| 243 | + |
| 244 | + # Rename .hex for true Releases on main repo |
| 245 | + - name: Rename Artifacts |
| 246 | + if: startsWith(github.ref, 'refs/tags/') |
| 247 | + run: | |
| 248 | + sudo apt -y install rename |
| 249 | + cd obj |
| 250 | + rename 's/_Build_.*/.hex/' *.hex |
| 251 | +
|
| 252 | + #Draft Releases on main Repo |
| 253 | + # could potentially change to ncipollo/release-action as well |
| 254 | + - name: Draft Release Main Repo |
| 255 | + if: contains(github.ref, 'releas') |
| 256 | + uses: ncipollo/release-action@v1 |
| 257 | + with: |
| 258 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 259 | + draft: true |
| 260 | + prerelease: true |
| 261 | + allowUpdates: true |
| 262 | + # tag: use the build Number, but we MUST manually change to version so that it creates a version-tag on release |
| 263 | + tag: ${{ env.VERSION }} |
| 264 | + artifacts: obj/*.hex |
| 265 | + artifactContentType: raw |
| 266 | + name: DRAFT / EmuFlight ${{ env.VERSION }} / GitHub Build ${{ github.run_number }} |
| 267 | + body: | |
| 268 | + ## EmuFlight ${{ env.VERSION }} |
| 269 | + ### Build ${{ github.run_number }} |
| 270 | + ### Commit SHA: ${{ needs.build.outputs.shortsha }} (${{ github.sha }}) |
| 271 | + ### BuildTag: ${{ needs.build.outputs.buildtag }} |
| 272 | + <details><summary>Changes in this Build:</summary> |
| 273 | + <!-- require single blank line below --> |
| 274 | +
|
| 275 | + ``` |
| 276 | + [insert commit history here] |
| 277 | + ``` |
| 278 | + </details> |
| 279 | + continue-on-error: false |
0 commit comments