|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + files: |
| 7 | + description: Newline separated list of files to build |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + esphome-version: |
| 11 | + description: Version of ESPHome to build with |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + default: latest |
| 15 | + release-summary: |
| 16 | + description: Summary of the release |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + default: "" |
| 20 | + release-url: |
| 21 | + description: URL to the release notes |
| 22 | + required: false |
| 23 | + type: string |
| 24 | + default: "" |
| 25 | + release-version: |
| 26 | + description: Version of the release |
| 27 | + required: false |
| 28 | + type: string |
| 29 | + default: "" |
| 30 | + combined-name: |
| 31 | + description: Combine all files into a single manifest under this name |
| 32 | + required: false |
| 33 | + type: string |
| 34 | + default: "" |
| 35 | + |
| 36 | + outputs: |
| 37 | + version: |
| 38 | + description: Version of the firmware generated |
| 39 | + value: ${{ jobs.prepare.outputs.version }} |
| 40 | + |
| 41 | +jobs: |
| 42 | + prepare: |
| 43 | + name: Prepare |
| 44 | + runs-on: ubuntu-latest |
| 45 | + outputs: |
| 46 | + files: ${{ steps.files-array.outputs.files }} |
| 47 | + version: ${{ steps.version.outputs.version }} |
| 48 | + artifact-prefix: ${{ steps.artifact-name.outputs.artifact-prefix }} |
| 49 | + steps: |
| 50 | + - name: Split files input into JSON array |
| 51 | + id: files-array |
| 52 | + run: | |
| 53 | + files=$(echo "${{ inputs.files }}" | jq -RcSn '[inputs | select(length>0)]') |
| 54 | + echo files=$files >> $GITHUB_OUTPUT |
| 55 | + - name: Generate version |
| 56 | + id: version |
| 57 | + run: | |
| 58 | + if [ -n "${{ inputs.release-version }}" ]; then |
| 59 | + version=${{ inputs.release-version }} |
| 60 | + else |
| 61 | + version=dev-$(date +'%Y%m%d-%H%M') |
| 62 | + fi |
| 63 | +
|
| 64 | + echo version=$version >> $GITHUB_OUTPUT |
| 65 | + - name: Generated random artifact prefix |
| 66 | + id: artifact-name |
| 67 | + run: | |
| 68 | + artifact_prefix=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 16; echo) |
| 69 | + echo artifact-prefix=$artifact_prefix >> $GITHUB_OUTPUT |
| 70 | +
|
| 71 | + build: |
| 72 | + name: ${{ matrix.file }} |
| 73 | + needs: [prepare] |
| 74 | + runs-on: ubuntu-latest |
| 75 | + strategy: |
| 76 | + fail-fast: false |
| 77 | + max-parallel: 3 |
| 78 | + matrix: |
| 79 | + file: ${{ fromJson(needs.prepare.outputs.files) }} |
| 80 | + steps: |
| 81 | + - name: Checkout code |
| 82 | + |
| 83 | + - name: Replace project version |
| 84 | + run: | |
| 85 | + sed -i "s/version: dev/version: ${{ needs.prepare.outputs.version }}/g" ${{ matrix.file }} |
| 86 | + - name: Build Firmware |
| 87 | + |
| 88 | + id: esphome-build |
| 89 | + with: |
| 90 | + yaml-file: ${{ matrix.file }} |
| 91 | + version: ${{ inputs.esphome-version }} |
| 92 | + complete-manifest: true |
| 93 | + release-summary: ${{ inputs.release-summary }} |
| 94 | + release-url: ${{ inputs.release-url }} |
| 95 | + - name: Move files for versioning |
| 96 | + run: | |
| 97 | + mkdir -p output/${{ needs.prepare.outputs.version }} |
| 98 | + mv ${{ steps.esphome-build.outputs.name }}/* output/${{ needs.prepare.outputs.version }}/ |
| 99 | + - name: Upload artifact |
| 100 | + |
| 101 | + with: |
| 102 | + name: ${{ inputs.combined-name != '' && format('{0}-{1}', needs.prepare.outputs.artifact-prefix, steps.esphome-build.outputs.name) || steps.esphome-build.outputs.original-name }} |
| 103 | + path: output |
| 104 | + |
| 105 | + combine: |
| 106 | + name: Combine manifests |
| 107 | + needs: |
| 108 | + - prepare |
| 109 | + - build |
| 110 | + runs-on: ubuntu-latest |
| 111 | + if: inputs.combined-name != '' |
| 112 | + steps: |
| 113 | + - name: Download artifacts |
| 114 | + |
| 115 | + with: |
| 116 | + path: files |
| 117 | + pattern: ${{ needs.prepare.outputs.artifact-prefix }}-* |
| 118 | + |
| 119 | + - name: Get artifact names |
| 120 | + id: artifacts |
| 121 | + run: | |
| 122 | + artifacts=$(ls --format=single-column files) |
| 123 | + echo "artifacts<<EOF" >> $GITHUB_OUTPUT |
| 124 | + echo "$artifacts" >> $GITHUB_OUTPUT |
| 125 | + echo "EOF" >> $GITHUB_OUTPUT |
| 126 | +
|
| 127 | + - name: Delete prefixed artifacts |
| 128 | + |
| 129 | + with: |
| 130 | + name: ${{ steps.artifacts.outputs.artifacts }} |
| 131 | + |
| 132 | + - name: Combine all parts into a single manifest |
| 133 | + run: | |
| 134 | + version="${{ needs.prepare.outputs.version }}" |
| 135 | + mkdir -p "output/$version" |
| 136 | + pushd files |
| 137 | + for device in *; do |
| 138 | + pushd $device |
| 139 | + pushd $version |
| 140 | + cp * "../../../output/$version/" |
| 141 | + cp manifest.json ../../../output/$version/manifest-`ls *.elf |cut -d. -f1`.json |
| 142 | + popd |
| 143 | + popd |
| 144 | + done |
| 145 | + popd |
| 146 | + jq -s '(.[0] | del(.builds)) + {"builds": (reduce .[].builds as $b ([]; . + $b))}' files/*/$version/manifest.json > output/$version/manifest.json |
| 147 | +
|
| 148 | + - name: Upload artifact |
| 149 | + |
| 150 | + with: |
| 151 | + name: ${{ inputs.combined-name }} |
| 152 | + path: output |
0 commit comments