Nightly Builds #423
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Nightly Builds | |
| # Runs every night at 11:30 PM | |
| on: | |
| schedule: | |
| - cron: "30 23 * * *" | |
| concurrency: | |
| group: ${{ github.workflow }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| jobs: | |
| check_tag_up_to_date: | |
| if: github.repository == 'techfoundrynz/Pubmote' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag_up_to_date: ${{ steps.compare_hashes.outputs.TAG_UP_TO_DATE }} | |
| tag_found: ${{ steps.check_for_tag.outputs.TAG_FOUND }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: master | |
| fetch-depth: 0 # Fetch all history for tags | |
| - name: Get latest commit hash from master | |
| id: get-master-hash | |
| run: | | |
| MASTER_HASH=$(git rev-parse master) | |
| echo "MASTER_HASH=$MASTER_HASH" >> $GITHUB_OUTPUT | |
| - name: Check if nightly tag exists | |
| id: check_for_tag | |
| run: | | |
| TAG_NAME="nightly" | |
| git fetch --tags | |
| if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then | |
| echo "TAG_FOUND=YES" >> $GITHUB_OUTPUT | |
| TAG_HASH=$(git rev-parse "$TAG_NAME") | |
| echo "TAG_HASH=$TAG_HASH" >> $GITHUB_OUTPUT | |
| else | |
| echo "TAG_FOUND=NO" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Compare master hash with nightly tag hash | |
| id: compare_hashes | |
| run: | | |
| if [[ "${{ steps.check_for_tag.outputs.TAG_FOUND }}" == "YES" && "${{ steps.get-master-hash.outputs.MASTER_HASH }}" == "${{ steps.check_for_tag.outputs.TAG_HASH }}" ]]; then | |
| echo "TAG_UP_TO_DATE=YES" >> $GITHUB_OUTPUT | |
| else | |
| echo "TAG_UP_TO_DATE=NO" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Exit if nightly tag is up to date | |
| if: ${{ steps.compare_hashes.outputs.TAG_UP_TO_DATE == 'YES' }} | |
| run: | | |
| echo "Nightly tag is already up to date with master. Skipping build." | |
| exit 0 | |
| delete_old_release: | |
| if: ${{ github.repository == 'techfoundrynz/Pubmote' && needs.check_tag_up_to_date.outputs.tag_up_to_date == 'NO' }} | |
| needs: check_tag_up_to_date | |
| permissions: | |
| # Write permission is required to create a github release | |
| contents: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: master | |
| - name: Check for Tag | |
| id: check_for_tag_in_delete_job | |
| run: | | |
| TAG_NAME="nightly" | |
| git fetch --tags | |
| if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then | |
| echo "TAG_FOUND=YES" >> $GITHUB_OUTPUT | |
| else | |
| echo "TAG_FOUND=NO" >> $GITHUB_OUTPUT | |
| fi | |
| # Delete the release if it already exists | |
| - name: Delete tag | |
| if: ${{ steps.check_for_tag_in_delete_job.outputs.TAG_FOUND == 'YES' }} | |
| run: gh release delete nightly --cleanup-tag | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Wait for 2 seconds | |
| run: sleep 2 | |
| build_and_release: | |
| # Access the output from the previous job | |
| if: ${{ github.repository == 'techfoundrynz/Pubmote' && needs.check_tag_up_to_date.outputs.tag_up_to_date == 'NO' }} | |
| needs: [check_tag_up_to_date, delete_old_release] | |
| permissions: | |
| contents: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: master | |
| - uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/pip | |
| ~/.platformio/.cache | |
| key: ${{ runner.os }}-pio | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.11 | |
| - name: Install PlatformIO Core | |
| run: pip install --upgrade platformio | |
| - name: Setup Rust for Xtensa | |
| uses: esp-rs/xtensa-toolchain@v1.5 | |
| with: | |
| default: false | |
| buildtargets: esp32s3 | |
| - name: Build PlatformIO Project | |
| run: | | |
| sed -i 's/build_type = debug/build_type = release/g' platformio.ini | |
| pio run | |
| env: | |
| PLATFORMIO_BUILD_FLAGS: | | |
| -D RELEASE_VARIANT=\"nightly\" | |
| -D RELEASES_AUTH_TOKEN=\"${{ secrets.RELEASES_AUTH_TOKEN }}\" | |
| - name: Get Current Date | |
| id: get_date | |
| run: echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT | |
| - name: Attach Files and Publish | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| *.zip | |
| *.bin | |
| name: "${{ steps.get_date.outputs.TODAY }} Nightly Build" | |
| prerelease: true | |
| tag_name: "nightly" | |
| fail_on_unmatched_files: true | |
| generate_release_notes: true |