|
| 1 | +# Adapted from NUT codeql.yml with inspiration taken from |
| 2 | +# https://javahelps.com/manage-github-artifact-storage-quota |
| 3 | +# regarding uploads of artifacts and clearing the way for them. |
| 4 | +# See also: |
| 5 | +# https://github.com/actions/upload-artifact |
| 6 | +# https://docs.github.com/en/actions/reference/workflows-and-actions/variables |
| 7 | +name: "GHA-01: Make dist and docs tarballs" |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches: [ "master", "FTY", "fightwarn", "FTY-obs" ] |
| 12 | + tags: |
| 13 | + - v* |
| 14 | + pull_request: |
| 15 | + # The branches below must be a subset of the branches above |
| 16 | + branches: [ "master", "FTY", "fightwarn", "FTY-obs" ] |
| 17 | + schedule: |
| 18 | + - cron: '15 12 * * 0' |
| 19 | + workflow_dispatch: |
| 20 | + # Allow manually running the action, e.g. if disabled after some quietness in the source |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: read |
| 24 | + issues: write |
| 25 | + pull-requests: write |
| 26 | + |
| 27 | +jobs: |
| 28 | + make-dist-tarballs: |
| 29 | + name: Make Dist and Docs Tarballs |
| 30 | + # FIXME: Prepare/maintain a container image with pre-installed |
| 31 | + # NUT build/tooling prereqs (save about 3 minutes per run!) |
| 32 | + runs-on: ubuntu-latest |
| 33 | + permissions: |
| 34 | + #actions: read |
| 35 | + actions: write |
| 36 | + #contents: read |
| 37 | + contents: write |
| 38 | + repository-projects: write |
| 39 | + security-events: write |
| 40 | + pull-requests: write |
| 41 | + issues: write |
| 42 | + |
| 43 | + strategy: |
| 44 | + fail-fast: false |
| 45 | + |
| 46 | + steps: |
| 47 | + # Post early so this would be about the top comment in the PR trail |
| 48 | + # (easy to see, contents replaced later) |
| 49 | + - name: "GHA-01: Make dist and docs tarballs - report download URL - t1" |
| 50 | + uses: thollander/actions-comment-pull-request@v3 |
| 51 | + # if: startsWith(github.ref, 'refs/pull/') |
| 52 | + continue-on-error: true |
| 53 | + with: |
| 54 | + comment-tag: latest-tarball |
| 55 | + message: Dist and Docs will be linked here after the "make dist" job completes. |
| 56 | + #github-token: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + |
| 58 | + - name: "GHA-01: Make dist and docs tarballs - report download URL - s1" |
| 59 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 60 | + # if: startsWith(github.ref, 'refs/pull/') |
| 61 | + continue-on-error: true |
| 62 | + with: |
| 63 | + header: latest-tarball-sticky |
| 64 | + only_create: true |
| 65 | + message: Dist and Docs will be linked here after the "make dist" job completes. |
| 66 | + #github-token: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + - name: Checkout repository |
| 69 | + uses: actions/checkout@v5 |
| 70 | + with: |
| 71 | + fetch-depth: 0 |
| 72 | + fetch-tags: true |
| 73 | + |
| 74 | + # https://github.com/marketplace/actions/substitute-string |
| 75 | + # Note it warns about "unexpected input(s)" with replacement tokens below, |
| 76 | + # as they are by design not predefined, as far as actions API is concened. |
| 77 | + # They still work for substitutions though. |
| 78 | + - uses: bluwy/substitute-string-action@v3 |
| 79 | + id: subst-github-ref-name |
| 80 | + with: |
| 81 | + _input-text: "${{ github.ref_name }}" |
| 82 | + " ": _ |
| 83 | + "/": _ |
| 84 | + - run: echo "${{ steps.subst-github-ref-name.outputs.result }}" |
| 85 | + |
| 86 | + # Make build identification more useful (so we use no fallbacks in script) |
| 87 | + - name: Try to get more Git metadata |
| 88 | + run: | |
| 89 | + git describe || { |
| 90 | + git remote -v || true |
| 91 | + git branch -a || true |
| 92 | + for R in `git remote` ; do git fetch $R master ; done || true |
| 93 | + git fetch --tags |
| 94 | + pwd ; ls -la |
| 95 | + echo "=== Known commits in history:" |
| 96 | + git log --oneline | wc -l |
| 97 | + echo "=== Recent commits in history:" |
| 98 | + git log -2 || true |
| 99 | + echo "=== Known tags:" |
| 100 | + git tag || true |
| 101 | + echo "=== Try to ensure 'git describe' works:" |
| 102 | + git describe || { |
| 103 | + git fetch --all && for R in `git remote` ; do for T in `git tag` ; do git fetch $R $T ; done ; done |
| 104 | + git describe || { |
| 105 | + TEST_REF="`git symbolic-ref --short HEAD 2>/dev/null || cat .git/HEAD`" && [ -n "${TEST_REF}" ] && git checkout master && git pull --all && git checkout "${TEST_REF}" |
| 106 | + git describe || true |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | +
|
| 111 | + # Using hints from https://askubuntu.com/questions/272248/processing-triggers-for-man-db |
| 112 | + # and our own docs/config-prereqs.txt |
| 113 | + # NOTE: Currently installing the MAX prerequisite footprint, |
| 114 | + # which for building just the docs may be a bit of an overkill. |
| 115 | + - name: NUT CI Prerequisite packages (Ubuntu, GCC) |
| 116 | + run: | |
| 117 | + echo "set man-db/auto-update false" | sudo debconf-communicate |
| 118 | + sudo dpkg-reconfigure man-db |
| 119 | + sudo apt update |
| 120 | + sudo apt install \ |
| 121 | + gcc g++ clang \ |
| 122 | + ccache time \ |
| 123 | + git perl curl \ |
| 124 | + make autoconf automake libltdl-dev libtool binutils \ |
| 125 | + valgrind \ |
| 126 | + cppcheck \ |
| 127 | + pkg-config \ |
| 128 | + libtool-bin \ |
| 129 | + python3 gettext python3-pyqt6 pyqt6-dev-tools \ |
| 130 | + aspell aspell-en \ |
| 131 | + asciidoc source-highlight python3-pygments dblatex \ |
| 132 | + libgd-dev \ |
| 133 | + systemd-dev \ |
| 134 | + libsystemd-dev \ |
| 135 | + libcppunit-dev \ |
| 136 | + libssl-dev libnss3-dev \ |
| 137 | + augeas-tools libaugeas-dev augeas-lenses \ |
| 138 | + libusb-dev libusb-1.0-0-dev \ |
| 139 | + libi2c-dev \ |
| 140 | + libmodbus-dev \ |
| 141 | + libsnmp-dev \ |
| 142 | + libpowerman0-dev \ |
| 143 | + libfreeipmi-dev libipmimonitoring-dev \ |
| 144 | + libavahi-common-dev libavahi-core-dev libavahi-client-dev \ |
| 145 | + libgpiod-dev \ |
| 146 | + bash dash ksh busybox \ |
| 147 | + libneon27-gnutls-dev \ |
| 148 | + build-essential git-core libi2c-dev i2c-tools lm-sensors \ |
| 149 | + || exit |
| 150 | + date > .timestamp-init |
| 151 | +
|
| 152 | + - name: Prepare ccache |
| 153 | + # Based on https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching#example-using-the-cache-action example |
| 154 | + id: cache-ccache |
| 155 | + uses: actions/cache@v4 |
| 156 | + env: |
| 157 | + compiler: 'CC=gcc CXX=g++' |
| 158 | + cache-name: cache-ccache-${{ env.compiler }} |
| 159 | + with: |
| 160 | + path: | |
| 161 | + ~/.ccache |
| 162 | + ~/.cache/ccache |
| 163 | + ~/.config/ccache/ccache.conf |
| 164 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/.timestamp-init') }} |
| 165 | + restore-keys: | |
| 166 | + ${{ runner.os }}-build-${{ env.cache-name }}- |
| 167 | + ${{ runner.os }}-build- |
| 168 | + ${{ runner.os }}- |
| 169 | +
|
| 170 | + - name: CCache stats before build |
| 171 | + run: | |
| 172 | + ccache -sv || ccache -s || echo "FAILED to read ccache info, oh well" |
| 173 | + rm -f .timestamp-init |
| 174 | +
|
| 175 | + - name: Debug gitlog2version processing |
| 176 | + run: bash -x ./tools/gitlog2version.sh || true |
| 177 | + |
| 178 | + - name: NUT CI Build Configuration |
| 179 | + env: |
| 180 | + compiler: 'CC=gcc CXX=g++' |
| 181 | + run: | |
| 182 | + PATH="/usr/lib/ccache:$PATH" ; export PATH |
| 183 | + CCACHE_COMPRESS=true; export CCACHE_COMPRESS |
| 184 | + ccache --version || true |
| 185 | + ( ${{env.compiler}} ; echo "=== CC: $CC => `command -v $CC` =>" ; $CC --version ; echo "=== CXX: $CXX => `command -v $CXX` =>" ; $CXX --version ) || true |
| 186 | + ./autogen.sh && \ |
| 187 | + ./configure --enable-warnings --enable-Werror --enable-Wcolor --with-all --with-dev --with-docs --enable-docs-changelog ${{env.compiler}} |
| 188 | +
|
| 189 | + # NOTE: In this scenario we do not build actually NUT in the main |
| 190 | + # checkout directory, at least not explicitly (recipe may generate |
| 191 | + # some files like man pages to fulfill the "dist" requirements; |
| 192 | + # for now this may generate some libs to figure out their IDs). |
| 193 | + # We do `make docs` to provide them as a separate tarball just |
| 194 | + # in case, later. |
| 195 | + # DO NOT `make dist-files` here as it includes `dist-sig` and |
| 196 | + # needs a GPG keychain with maintainers' secrets deployed locally. |
| 197 | + - name: NUT CI Build to create "dist" tarball and related files |
| 198 | + env: |
| 199 | + compiler: 'CC=gcc CXX=g++' |
| 200 | + run: | |
| 201 | + PATH="/usr/lib/ccache:$PATH" ; export PATH |
| 202 | + CCACHE_COMPRESS=true; export CCACHE_COMPRESS |
| 203 | + ccache --version || true |
| 204 | + ( ${{env.compiler}} ; echo "=== CC: $CC => `command -v $CC` =>" ; $CC --version ; echo "=== CXX: $CXX => `command -v $CXX` =>" ; $CXX --version ) || true |
| 205 | + make -s -j 8 dist dist-hash |
| 206 | +
|
| 207 | + - name: NUT CI Build to verify "dist" tarball build |
| 208 | + env: |
| 209 | + compiler: 'CC=gcc CXX=g++' |
| 210 | + run: | |
| 211 | + PATH="/usr/lib/ccache:$PATH" ; export PATH |
| 212 | + CCACHE_COMPRESS=true; export CCACHE_COMPRESS |
| 213 | + ccache --version || true |
| 214 | + ( ${{env.compiler}} ; echo "=== CC: $CC => `command -v $CC` =>" ; $CC --version ; echo "=== CXX: $CXX => `command -v $CXX` =>" ; $CXX --version ) || true |
| 215 | + make -s -j 8 distcheck |
| 216 | +
|
| 217 | + - name: CCache stats after distcheck |
| 218 | + run: ccache -sv || ccache -s || echo "FAILED to read ccache info, oh well" |
| 219 | + |
| 220 | + - name: NUT CI Build to package complex docs (not part of dist tarball) |
| 221 | + run: | |
| 222 | + make -s -j 8 dist-docs |
| 223 | +
|
| 224 | + # Inspired by https://javahelps.com/manage-github-artifact-storage-quota |
| 225 | + # Note that the code below wipes everything matched by the filter! |
| 226 | + # We may want another script block (after this cleanup of obsolete data) |
| 227 | + # to iterate clearing the way build by build until there's X MB available |
| 228 | + # (at least 12MB as of Nov 2025). |
| 229 | + - if: env.GITHUB_REF_TYPE != 'tag' && steps.subst-github-ref-name.outputs.result != 'master' |
| 230 | + name: Delete Old Artifacts for this feature branch/PR |
| 231 | + uses: actions/github-script@v6 |
| 232 | + id: delete_old_artifact_for_pr |
| 233 | + continue-on-error: true |
| 234 | + with: |
| 235 | + script: | |
| 236 | + const res = await github.rest.actions.listArtifactsForRepo({ |
| 237 | + owner: context.repo.owner, |
| 238 | + repo: context.repo.repo, |
| 239 | + }) |
| 240 | +
|
| 241 | + res.data.artifacts |
| 242 | + .filter(({ name }) => name === 'NUT-tarballs-${{ steps.subst-github-ref-name.outputs.result }}') |
| 243 | + .forEach(({ id }) => { |
| 244 | + github.rest.actions.deleteArtifact({ |
| 245 | + owner: context.repo.owner, |
| 246 | + repo: context.repo.repo, |
| 247 | + artifact_id: id, |
| 248 | + }) |
| 249 | + }) |
| 250 | +
|
| 251 | + - name: Upload tarball and its checksum artifacts |
| 252 | + uses: actions/upload-artifact@v4 |
| 253 | + id: upload_artifact |
| 254 | + with: |
| 255 | + name: NUT-tarballs-${{ steps.subst-github-ref-name.outputs.result }} |
| 256 | + path: | |
| 257 | + nut-*.tar* |
| 258 | + compression-level: 0 |
| 259 | + overwrite: true |
| 260 | + |
| 261 | + # https://github.com/thollander/actions-comment-pull-request |
| 262 | + # FIXME: Something that adds/updates Github Checks would be better |
| 263 | + # as it would be seen in the list attached to a status icon of any |
| 264 | + # build (e.g. history of master branch) |
| 265 | + - name: "GHA-01: Make dist and docs tarballs - report download URL - t2" |
| 266 | + uses: thollander/actions-comment-pull-request@v3 |
| 267 | + # if: startsWith(github.ref, 'refs/pull/') |
| 268 | + continue-on-error: true |
| 269 | + with: |
| 270 | + comment-tag: latest-tarball |
| 271 | + message: Dist and Docs [NUT-tarballs-${{ steps.subst-github-ref-name.outputs.result }}.zip}](${{ steps.upload_artifact.outputs.artifact-url }}) are available for commit ${{ github.sha }} |
| 272 | + #github-token: ${{ secrets.GITHUB_TOKEN }} |
| 273 | + |
| 274 | + # https://github.com/marocchino/sticky-pull-request-comment |
| 275 | + - name: "GHA-01: Make dist and docs tarballs - report download URL - s2" |
| 276 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 277 | + # if: startsWith(github.ref, 'refs/pull/') |
| 278 | + continue-on-error: true |
| 279 | + with: |
| 280 | + header: latest-tarball-sticky |
| 281 | + only_create: true |
| 282 | + message: Dist and Docs [NUT-tarballs-${{ steps.subst-github-ref-name.outputs.result }}.zip}](${{ steps.upload_artifact.outputs.artifact-url }}) are available for commit ${{ github.sha }} |
0 commit comments