aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/ci.yml
blob: d3ca6be9771c9f830459c4a59068c4cb1e5432e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: CI

on:
  push:
    branches: [main]
    tags: ['v*']
  pull_request:
  workflow_dispatch:

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ghcr.io/sulfurnitride/fluorine-builder

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Log in to GHCR
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build Docker image
        uses: docker/build-push-action@v6
        with:
          context: docker
          file: docker/Dockerfile
          load: true
          tags: fluorine-builder:latest
          cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
          cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max

      - name: Restore ccache
        uses: actions/cache@v4
        with:
          path: ~/.cache/fluorine-ccache
          key: ccache-${{ runner.os }}-${{ github.sha }}
          restore-keys: |
            ccache-${{ runner.os }}-

      - name: Build inside container
        run: |
          mkdir -p ~/.cache/fluorine-ccache
          docker run --rm \
            -v "${{ github.workspace }}:/src:rw" \
            -v "$HOME/.cache/fluorine-ccache:/ccache:rw" \
            -e CCACHE_DIR=/ccache \
            -e BUILD_MODE=tarball \
            -w /src \
            fluorine-builder:latest \
            bash /src/docker/build-inner.sh

      - name: Collect artifacts
        run: |
          mkdir -p artifact
          if [ -f build/fluorine-manager.tar.gz ]; then
            cp build/fluorine-manager.tar.gz artifact/
          fi
          ls -lh artifact/

      - name: Upload tarball
        uses: actions/upload-artifact@v4
        with:
          name: Fluorine-Manager
          path: artifact/fluorine-manager.tar.gz
          if-no-files-found: warn

  release:
    if: startsWith(github.ref, 'refs/tags/v')
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          name: Fluorine-Manager
          path: artifact/

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          files: artifact/fluorine-manager.tar.gz
          generate_release_notes: true