|
| 1 | +name: Build C artifact + Release (live-chart-c) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Check out upstream live-chart |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + repository: lcallarec/live-chart |
| 20 | + ref: master |
| 21 | + path: live-chart |
| 22 | + |
| 23 | + - name: Install build dependencies |
| 24 | + run: | |
| 25 | + sudo apt-get update |
| 26 | + sudo apt-get install -y \ |
| 27 | + build-essential meson ninja-build valac pkg-config jq zip \ |
| 28 | + libgtk-4-dev libglib2.0-dev libgee-0.8-dev libcairo2-dev \ |
| 29 | + gobject-introspection libgirepository1.0-dev |
| 30 | +
|
| 31 | + - name: Meson setup |
| 32 | + working-directory: live-chart |
| 33 | + run: meson setup build --buildtype=release |
| 34 | + |
| 35 | + - name: Read version |
| 36 | + id: ver |
| 37 | + working-directory: live-chart |
| 38 | + run: | |
| 39 | + VERSION=$(meson introspect --projectinfo build | jq -r '.version') |
| 40 | + echo "version=$VERSION" >>"$GITHUB_OUTPUT" |
| 41 | + [[ "$VERSION" == v* ]] && TAG="$VERSION" || TAG="v$VERSION" |
| 42 | + echo "tag=$TAG" >>"$GITHUB_OUTPUT" |
| 43 | +
|
| 44 | + - name: Meson compile |
| 45 | + working-directory: live-chart |
| 46 | + run: meson compile -C build |
| 47 | + |
| 48 | + - name: Emit C sources (valac --ccode) |
| 49 | + working-directory: live-chart |
| 50 | + run: | |
| 51 | + rm -rf c-emitted && mkdir c-emitted |
| 52 | + VALA_FILES=$(find . \ |
| 53 | + -path ./build -prune -o \ |
| 54 | + -path ./c-emitted -prune -o \ |
| 55 | + -path ./examples -prune -o \ |
| 56 | + -path ./builder -prune -o \ |
| 57 | + -path ./tests -prune -o \ |
| 58 | + -type f -name '*.vala' -print | sort) |
| 59 | + valac --ccode \ |
| 60 | + --directory=c-emitted \ |
| 61 | + --header=c-emitted/livechart.h \ |
| 62 | + --pkg gtk4 --pkg gee-0.8 --pkg cairo --pkg gobject-2.0 --pkg glib-2.0 \ |
| 63 | + $VALA_FILES |
| 64 | + echo "Emitted C files: $(find c-emitted -name '*.c' | wc -l)" |
| 65 | +
|
| 66 | + - name: Build static lib (pure gcc) |
| 67 | + working-directory: live-chart |
| 68 | + run: | |
| 69 | + sudo rm -f /usr/bin/valac || true |
| 70 | + cd c-emitted |
| 71 | + CFLAGS="$(pkg-config --cflags gtk4 gee-0.8 gobject-2.0 glib-2.0 cairo)" |
| 72 | + mkdir -p obj |
| 73 | + while IFS= read -r -d '' CFILE; do |
| 74 | + OBJ="obj/$(echo "${CFILE#./}" | tr '/.' '__').o" |
| 75 | + gcc -fPIC $CFLAGS -I. -c "$CFILE" -o "$OBJ" |
| 76 | + done < <(find . -type f -name '*.c' -print0) |
| 77 | + ar rcs liblivechart.a obj/*.o |
| 78 | + ls -lh liblivechart.a |
| 79 | +
|
| 80 | + - name: Create release ZIP |
| 81 | + id: zip |
| 82 | + working-directory: live-chart |
| 83 | + run: | |
| 84 | + ZIP="live-chart-c-${{ steps.ver.outputs.version }}.zip" |
| 85 | + zip -r "$ZIP" c-emitted |
| 86 | + echo "zip=$ZIP" >>"$GITHUB_OUTPUT" |
| 87 | +
|
| 88 | + - name: Upload build artifact |
| 89 | + uses: actions/upload-artifact@v4 |
| 90 | + with: |
| 91 | + name: live-chart-c-only-${{ steps.ver.outputs.version }} |
| 92 | + path: live-chart/${{ steps.zip.outputs.zip }} |
| 93 | + |
| 94 | + - name: Purge old assets |
| 95 | + if: ${{ github.event_name != 'pull_request' }} |
| 96 | + env: |
| 97 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + TAG: ${{ steps.ver.outputs.tag }} |
| 99 | + run: | |
| 100 | + set -e |
| 101 | + if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then |
| 102 | + gh api repos/$GITHUB_REPOSITORY/releases/tags/$TAG \ |
| 103 | + | jq -r '.assets[].id' \ |
| 104 | + | while read -r id; do |
| 105 | + gh api -X DELETE repos/$GITHUB_REPOSITORY/releases/assets/$id |
| 106 | + done |
| 107 | + fi |
| 108 | +
|
| 109 | + - name: Publish GitHub Release |
| 110 | + if: ${{ github.event_name != 'pull_request' }} |
| 111 | + uses: softprops/action-gh-release@v2 |
| 112 | + with: |
| 113 | + tag_name: ${{ steps.ver.outputs.tag }} |
| 114 | + name: live-chart-c ${{ steps.ver.outputs.version }} |
| 115 | + generate_release_notes: true |
| 116 | + allowUpdates: true |
| 117 | + files: live-chart/${{ steps.zip.outputs.zip }} |
| 118 | + env: |
| 119 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments