aboutsummaryrefslogtreecommitdiffstats
path: root/.github/workflows/tools.yml
blob: 2661782f427fba9fcd07830db730e0b4efd48c45 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Build host tools

on:
  pull_request:
    paths:
      - 'tools/**'
      - '.github/workflows/tools.yml'
  push:
    paths:
      - 'tools/**'
      - '.github/workflows/tools.yml'

permissions:
  contents: read

jobs:
  build-macos-latest:
    if: github.event_name != 'push'
    runs-on: macos-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          path: openwrt

      - name: Setup MacOS
        run: |
          echo "WORKPATH=/Volumes/OpenWrt" >> "$GITHUB_ENV"
          hdiutil create -size 20g -type SPARSE -fs "Case-sensitive HFS+" -volname OpenWrt OpenWrt.sparseimage
          hdiutil attach OpenWrt.sparseimage
          mv "$GITHUB_WORKSPACE/openwrt" /Volumes/OpenWrt/

      - name: Install required prereq on MacOS
        working-directory: ${{ env.WORKPATH }}/openwrt
        run: |
          brew install \
            autoconf \
            automake \
            coreutils \
            diffutils \
            findutils \
            gawk \
            gettext \
            git-extras \
            gmp \
            gnu-getopt \
            gnu-sed \
            gnu-tar \
            grep \
            libidn2 \
            libunistring \
            m4 \
            make \
            mpfr \
            ncurses \
            openssl@1.1 \
            pcre \
            pkg-config \
            quilt \
            readline \
            wget \
            zstd

            echo "/bin" >> "$GITHUB_PATH"
            echo "/sbin/Library/Apple/usr/bin" >> "$GITHUB_PATH"
            echo "/usr/bin" >> "$GITHUB_PATH"
            echo "/usr/local/bin" >> "$GITHUB_PATH"
            echo "/usr/local/opt/coreutils/bin" >> "$GITHUB_PATH"
            echo "/usr/local/opt/findutils/libexec/gnubin" >> "$GITHUB_PATH"
            echo "/usr/local/opt/gettext/bin" >> "$GITHUB_PATH"
            echo "/usr/local/opt/gnu-getopt/bin" >> "$GITHUB_PATH"
            echo "/usr/local/opt/make/libexec/gnubin" >> "$GITHUB_PATH"
            echo "/usr/local/opt/make/libexec/gnubin" >> "$GITHUB_PATH"
            echo "/usr/sbin" >> "$GITHUB_PATH"

      - name: Make prereq
        working-directory: ${{ env.WORKPATH }}/openwrt
        run: make defconfig

      - name: Build tools MacOS
        working-directory: ${{ env.WORKPATH }}/openwrt
        run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh

      - name: Upload logs
        if: always()
        uses: actions/upload-artifact@v2
        with:
          name: macos-latest-logs
          path: ${{ env.WORKPATH }}/openwrt/logs

      - name: Upload config
        if: always()
        uses: actions/upload-artifact@v2
        with:
          name: macos-latest-config
          path: ${{ env.WORKPATH }}/openwrt/.config

  build-linux-buildbot:
    runs-on: ubuntu-latest
    container: registry.gitlab.com/openwrt/buildbot/buildworker-3.4.1

    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          path: 'openwrt'

      - name: Fix permission
        run: |
          chown -R buildbot:buildbot openwrt

      - name: Set configs for tools container
        if: github.event_name == 'push'
        shell: su buildbot -c "sh -e {0}"
        working-directory: openwrt
        run: |
          touch .config
          echo CONFIG_DEVEL=y >> .config
          echo CONFIG_AUTOREMOVE=y >> .config
          echo CONFIG_CCACHE=y >> .config

      - name: Make prereq
        shell: su buildbot -c "sh -e {0}"
        working-directory: openwrt
        run: make defconfig

      - name: Build tools BuildBot Container
        shell: su buildbot -c "sh -e {0}"
        working-directory: openwrt
        run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh

      - name: Upload logs
        if: always()
        uses: actions/upload-artifact@v2
        with:
          name: linux-buildbot-logs
          path: openwrt/logs

      - name: Upload config
        if: always()
        uses: actions/upload-artifact@v2
        with:
          name: linux-buildbot-config
          path: openwrt/.config

      - name: Archive prebuilt tools
        if: github.event_name == 'push'
        shell: su buildbot -c "sh -e {0}"
        working-directory: openwrt
        run: tar --mtime=now -cf tools.tar staging_dir/host build_dir/host dl

      - name: Upload prebuilt tools
        if: github.event_name == 'push'
        uses: actions/upload-artifact@v2
        with:
          name: linux-buildbot-prebuilt-tools
          path: openwrt/tools.tar
          retention-days: 1

  push-tools-container:
    needs: build-linux-buildbot
    runs-on: ubuntu-latest
    if: github.event_name == 'push'

    permissions:
      contents: read
      packages: write

    steps:
      - name: Set lower case owner name
        env:
          OWNER: ${{ github.repository_owner }}
        run: |
          echo "OWNER_LC=${OWNER,,}" >> "$GITHUB_ENV"

      - name: Checkout
        uses: actions/checkout@v3
        with:
          path: 'openwrt'

      - name: Download prebuilt tools from build job
        uses: actions/download-artifact@v2
        with:
          name: linux-buildbot-prebuilt-tools
          path: openwrt

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push
        uses: docker/build-push-action@v3
        with:
          context: openwrt
          push: true
          tags: ghcr.io/${{ env.OWNER_LC }}/tools:latest
          file: openwrt/.github/workflows/Dockerfile.tools