|
| 1 | +name: Build-and-Release-Satellite-Firmware |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - staging |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + tag: |
| 11 | + description: 'Tag for the release (optional). If not provided, it will be auto-generated.' |
| 12 | + required: false |
| 13 | + |
| 14 | +env: |
| 15 | + DEFAULT_PYTHON: "3.9" |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + pull-requests: read |
| 19 | +jobs: |
| 20 | + prepare: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + outputs: |
| 23 | + commit_id: ${{ steps.dump.outputs.commit }} |
| 24 | + previous_tag: ${{ steps.dump.outputs.previous_tag }} |
| 25 | + next_tag: ${{ steps.set_release_tag.outputs.release_tag }} |
| 26 | + steps: |
| 27 | + - name: Check out code from GitHub |
| 28 | + |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - name: Set Manual Tag (if provided) |
| 33 | + id: set_tag |
| 34 | + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag != '' }} |
| 35 | + run: echo "manual_tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT |
| 36 | + |
| 37 | + - name: Bump version |
| 38 | + # if manual tag is provided, use it |
| 39 | + if: ${{ !steps.set_tag.outputs.manual_tag }} |
| 40 | + uses: anothrNick/[email protected] |
| 41 | + id: bump |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + # To create a major bump add #major to commit message |
| 45 | + DEFAULT_BUMP: 'patch' |
| 46 | + WITH_V: true |
| 47 | + PRERELEASE: ${{ github.ref_name != 'main' }} |
| 48 | + PRERELEASE_SUFFIX: ${{ github.ref_name == 'staging' && 'beta' || 'alpha' }} |
| 49 | + DRY_RUN: true # Prevent action from pushing the tag. |
| 50 | + INITIAL_VERSION: 0.0.0 |
| 51 | + |
| 52 | + - name: Set tag for release |
| 53 | + if: ${{ steps.set_tag.outputs.manual_tag || steps.bump.outputs.tag }} |
| 54 | + id: set_release_tag |
| 55 | + run: | |
| 56 | + if [ -z "${{ steps.set_tag.outputs.manual_tag }}" ]; then |
| 57 | + echo "release_tag=${{ steps.bump.outputs.tag }}" >> $GITHUB_OUTPUT |
| 58 | + else |
| 59 | + echo "release_tag=${{ steps.set_tag.outputs.manual_tag }}" >> $GITHUB_OUTPUT |
| 60 | + fi |
| 61 | +
|
| 62 | + - id: dump |
| 63 | + name: Set outputs |
| 64 | + run: | |
| 65 | + echo "gh_env=${{ github.ref_name == 'main' && 'production' || github.ref_name == 'staging' && 'beta' || 'alpha' }}" >> $GITHUB_OUTPUT |
| 66 | + echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT |
| 67 | + echo "long_version=${{ steps.set_release_tag.outputs.release_tag }}_$(date +%Y-%m-%d)_$(git rev-parse HEAD)" >> $GITHUB_OUTPUT |
| 68 | + echo "label_version=$(echo "${{ steps.set_release_tag.outputs.release_tag }}" | sed 's/\./dot/g' | sed 's/-/dash/g')" >> $GITHUB_OUTPUT |
| 69 | + echo "previous_tag=$(git describe --abbrev=0 --tags)" >> $GITHUB_OUTPUT |
| 70 | + echo "files=$(ls config/satellite*.yaml | jq --slurp --raw-input )" >> $GITHUB_OUTPUT |
| 71 | +
|
| 72 | + - name: Update YAML files |
| 73 | + run: | |
| 74 | + files=$(echo ${{ steps.dump.outputs.files }} \ |
| 75 | + | sed 's/^"//' \ |
| 76 | + | sed 's/"$//' \ |
| 77 | + | sed 's/\\n/\n/g') |
| 78 | + tag="${{ steps.set_release_tag.outputs.release_tag }}" |
| 79 | + for file in $files; do |
| 80 | + echo "Updating $file" |
| 81 | + # Use sed to match the esp32_fw_version line and replace its value |
| 82 | + sed -i "s/^\(\s*esp32_fw_version:\s*\).*/\1\"${tag}\"/" "$file" |
| 83 | + done |
| 84 | + build-firmware: |
| 85 | + name: Build Firmware |
| 86 | + needs: |
| 87 | + - prepare |
| 88 | + uses: esphome/workflows/.github/workflows/build.yml@main |
| 89 | + with: |
| 90 | + files: | |
| 91 | + config/satellite1.yaml |
| 92 | + esphome-version: 2024.11.2 |
| 93 | + release-version: ${{ needs.prepare.outputs.next_tag }} |
| 94 | + |
| 95 | + push-tag: |
| 96 | + name: Push tag to repository and build changelog. |
| 97 | + needs: |
| 98 | + - prepare |
| 99 | + - build-firmware |
| 100 | + runs-on: ubuntu-latest |
| 101 | + outputs: |
| 102 | + changelog: ${{ steps.changelog.outputs.changelog }} |
| 103 | + |
| 104 | + steps: |
| 105 | + - uses: actions/checkout@v3 |
| 106 | + with: |
| 107 | + fetch-depth: 0 |
| 108 | + |
| 109 | + - name: Bump version and push tag |
| 110 | + if: ${{ !github.event.inputs.tag }} |
| 111 | + uses: anothrNick/[email protected] |
| 112 | + id: bump |
| 113 | + env: |
| 114 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 115 | + # To create a major bump add #major to commit message |
| 116 | + DEFAULT_BUMP: 'patch' |
| 117 | + WITH_V: true |
| 118 | + PRERELEASE: ${{ github.ref_name != 'main' }} |
| 119 | + PRERELEASE_SUFFIX: ${{ github.ref_name == 'staging' && 'beta' || 'alpha' }} |
| 120 | + DRY_RUN: false # Set the tag to the commit. |
| 121 | + INITIAL_VERSION: 0.0.0 |
| 122 | + |
| 123 | + - name: Release Changelog Builder |
| 124 | + id: changelog |
| 125 | + uses: mikepenz/release-changelog-builder-action@v5 |
| 126 | + with: |
| 127 | + fromTag: ${{ needs.prepare.outputs.previous_tag }} |
| 128 | + |
| 129 | + create_release: |
| 130 | + name: Create Release |
| 131 | + # only build release for staging and main branches |
| 132 | + # if: github.ref_name == 'main' || github.ref_name == 'staging' |
| 133 | + needs: |
| 134 | + - push-tag |
| 135 | + - prepare |
| 136 | + runs-on: ubuntu-latest |
| 137 | + steps: |
| 138 | + - name: Download artifacts |
| 139 | + uses: actions/download-artifact@v4 |
| 140 | + with: |
| 141 | + path: files |
| 142 | + |
| 143 | + - name: Create zip files |
| 144 | + run: | |
| 145 | + mkdir -p build |
| 146 | + echo "Copying all files to build directory" |
| 147 | + find files -name "*.bin" -exec cp {} build/ \; |
| 148 | +
|
| 149 | + - name: Create release |
| 150 | + uses: softprops/action-gh-release@v2 |
| 151 | + with: |
| 152 | + files: build/*.bin |
| 153 | + generate_release_notes: true |
| 154 | + append_body: true |
| 155 | + body: ${{ needs.push-tag.outputs.changelog }} |
| 156 | + tag_name: ${{ needs.prepare.outputs.next_tag }} |
| 157 | + |
| 158 | + - name: Update Documentation |
| 159 | + run: | |
| 160 | + curl -X POST \ |
| 161 | + -H "Accept: application/vnd.github+json" \ |
| 162 | + -H "Authorization: Bearer ${{ secrets.SECOND_REPO_PAT }}" \ |
| 163 | + https://api.github.com/repos/FutureProofHomes/Documentation/actions/workflows/update-binaries-esp32.yaml/dispatches \ |
| 164 | + -d '{"ref":"main", "inputs": {"esphome_release_tag": "${{ needs.prepare.outputs.next_tag }}"}}' |
| 165 | + env: |
| 166 | + SECOND_REPO_PAT: ${{ secrets.SECOND_REPO_PAT }} |
0 commit comments