|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + # Build on changes to this workflow files in PRs to test proposed changes |
| 6 | + paths: |
| 7 | + - '.github/workflows/build.yml' |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + - dev |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + os-ref: |
| 15 | + description: The seedsigner-os ref (tag/branch/sha1) to use |
| 16 | + default: main |
| 17 | + required: true |
| 18 | + |
| 19 | +# Increment this number as part of a PR to trigger an image build for the PR |
| 20 | +# trigger = 0 |
| 21 | + |
| 22 | +jobs: |
| 23 | + build: |
| 24 | + name: build |
| 25 | + runs-on: ubuntu-latest |
| 26 | + # Prevent resource consuming cron triggered runs in forks |
| 27 | + if: (!github.event.repository.fork || github.event_name == 'workflow_dispatch') |
| 28 | + strategy: |
| 29 | + fail-fast: false |
| 30 | + matrix: |
| 31 | + target: [ "pi0", "pi2", "pi02w", "pi4" ] |
| 32 | + steps: |
| 33 | + - name: checkout seedsigner-os |
| 34 | + uses: actions/checkout@v3 |
| 35 | + with: |
| 36 | + repository: "seedsigner/seedsigner-os" |
| 37 | + # use the os-ref input parameter in case of workflow_dispatch or default to main in case of cron triggers |
| 38 | + ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.os-ref || 'main' }} |
| 39 | + submodules: true |
| 40 | + path: "seedsigner-os" |
| 41 | + # get full history + tags for "git describe" |
| 42 | + fetch-depth: 0 |
| 43 | + |
| 44 | + - name: checkout source |
| 45 | + uses: actions/checkout@v3 |
| 46 | + with: |
| 47 | + # ref defaults to repo default-branch=dev (cron) or SHA of event (workflow_dispatch) |
| 48 | + path: "seedsigner-os/opt/rootfs-overlay/opt" |
| 49 | + # get full history + tags for "git describe" |
| 50 | + fetch-depth: 0 |
| 51 | + |
| 52 | + - name: Get and set meta data |
| 53 | + run: | |
| 54 | + # The builder_hash (seedsigner-os hash) for the cache action step key |
| 55 | + echo "builder_hash=$(git -C seedsigner-os rev-parse --short HEAD)"| tee -a $GITHUB_ENV |
| 56 | +
|
| 57 | + # Derive tag based versions, like 0.7.0-40-g0424967 (=$tag-$number-of-commits-since-tag-$short-sha1), |
| 58 | + # or just e.g. 0.7.0, if we are exactly on a 0.7.0 tagged commit. |
| 59 | + # --always to fall back to commit sha, if no tag present like in partial forks of the repo |
| 60 | + os_version="$(git -C seedsigner-os describe --tags --always)" |
| 61 | + source_version="$(git -C seedsigner-os/opt/rootfs-overlay/opt describe --tags --always)" |
| 62 | +
|
| 63 | + # Combine seedsigner and seedsigner-os version into one version string and squash the versions, if |
| 64 | + # they are identical: So os_version=0.7.0 + source_version=0.7.0 combine to just only "0.7.0", |
| 65 | + # whereas os_version=0.6.0-61-g9fafebe + source_version=0.7.0-40-g0424967 combine to "os0.6.0-61-g9fafebe_sw0.7.0-40-g0424967" |
| 66 | + if [ "${os_version}" = "${source_version}" ]; then |
| 67 | + # seedsigner + seedsigner_os have the same tag |
| 68 | + echo "img_version=${source_version}"| tee -a $GITHUB_ENV |
| 69 | + else |
| 70 | + echo "img_version=os${os_version}_sw${source_version}"| tee -a $GITHUB_ENV |
| 71 | + fi |
| 72 | +
|
| 73 | + - name: delete unnecessary files |
| 74 | + run: | |
| 75 | + cd seedsigner-os/opt/rootfs-overlay/opt |
| 76 | + find . -mindepth 1 -maxdepth 1 ! -name src -exec rm -rf {} + |
| 77 | + ls -la . |
| 78 | + ls -la src |
| 79 | +
|
| 80 | + - name: restore build cache |
| 81 | + uses: actions/cache@v3 |
| 82 | + # Caching reduces the build time to ~50% (currently: ~30 mins instead of ~1 hour, |
| 83 | + # while consuming ~850 MB storage space). |
| 84 | + with: |
| 85 | + path: | |
| 86 | + ~/.buildroot-ccache/ |
| 87 | + seedsigner-os/buildroot_dl |
| 88 | + key: build-cache-${{ matrix.target }}-${{ env.builder_hash }} |
| 89 | + restore-keys: | |
| 90 | + build-cache-${{ matrix.target }}- |
| 91 | +
|
| 92 | + - name: build |
| 93 | + run: | |
| 94 | + cd seedsigner-os/opt |
| 95 | + ./build.sh --${{ matrix.target }} --skip-repo --no-clean |
| 96 | +
|
| 97 | + - name: list image (before rename) |
| 98 | + run: | |
| 99 | + ls -la seedsigner-os/images |
| 100 | +
|
| 101 | + - name: rename image |
| 102 | + run: | |
| 103 | + cd seedsigner-os/images |
| 104 | + mv seedsigner_os*.img seedsigner_os.${{ env.img_version }}.${{ matrix.target }}.img |
| 105 | +
|
| 106 | + - name: print sha256sum |
| 107 | + run: | |
| 108 | + cd seedsigner-os/images |
| 109 | + sha256sum *.img |
| 110 | +
|
| 111 | + - name: list image (after rename) |
| 112 | + run: | |
| 113 | + ls -la seedsigner-os/images |
| 114 | +
|
| 115 | + - name: upload images |
| 116 | + uses: actions/upload-artifact@v3 |
| 117 | + with: |
| 118 | + name: seedsigner_os_images |
| 119 | + path: "seedsigner-os/images/*.img" |
| 120 | + if-no-files-found: error |
| 121 | + # maximum 90 days retention |
| 122 | + retention-days: 90 |
| 123 | + |
| 124 | + sha256sum: |
| 125 | + name: calculate sha256sum |
| 126 | + runs-on: ubuntu-latest |
| 127 | + needs: build |
| 128 | + steps: |
| 129 | + - name: download images |
| 130 | + uses: actions/download-artifact@v3 |
| 131 | + with: |
| 132 | + name: seedsigner_os_images |
| 133 | + path: images |
| 134 | + |
| 135 | + - name: list images |
| 136 | + run: | |
| 137 | + ls -la images |
| 138 | +
|
| 139 | + - name: get seedsigner latest commit hash |
| 140 | + id: get-seedsigner-hash |
| 141 | + run: | |
| 142 | + git init |
| 143 | + echo "source_hash=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV |
| 144 | +
|
| 145 | + - name: write sha256sum |
| 146 | + run: | |
| 147 | + cd images |
| 148 | + sha256sum *.img > seedsigner_os.${{ env.source_hash }}.sha256 |
| 149 | +
|
| 150 | + - name: upload checksums |
| 151 | + uses: actions/upload-artifact@v3 |
| 152 | + with: |
| 153 | + name: seedsigner_os_images |
| 154 | + path: "images/*.sha256" |
| 155 | + if-no-files-found: error |
| 156 | + # maximum 90 days retention |
| 157 | + retention-days: 90 |
0 commit comments