Merge pull request #3765 from geany/dependabot/github_actions/actions/upload-artifact-4
[geany-mirror.git] / .github / workflows / build.yml
blobfd8f14a67484655971ee915065f817729635711b
2 # Copyright:    2021, The Geany contributors
3 # License:              GNU GPL v2 or later
5 name: CI Build
7 on:
8   push:
9     branches:
10       - master
11   pull_request:
12     branches:
13       - master
14   workflow_dispatch:
16 # cancel already running builds of the same branch or pull request
17 concurrency:
18   group: ci-${{ github.head_ref }} || concat(${{ github.ref }}
19   cancel-in-progress: true
21 env:
22   CFLAGS: -g -O2 -Werror=pointer-arith -Werror=implicit-function-declaration
23   CCACHE_DIR: ${{ github.workspace }}/.ccache
24   CCACHE_COMPRESS: true
25   CCACHE_MAXSIZE: 1G
26   PYTHON: python3
27   JOBS: 2
28   DEBUG: 0
30 jobs:
31   linux:
32     name: Linux Build (BINRELOC=${{ matrix.binreloc }})
33     runs-on: ubuntu-20.04
35     strategy:
36       fail-fast: false
37       matrix:
38         include:
39           - binreloc: no
40           - binreloc: yes
42     env:
43       CONFIGURE_FLAGS: --enable-binreloc=${{ matrix.binreloc }}
44       CC: ccache gcc
45       CXX: ccache g++
47     steps:
48       - uses: actions/checkout@v4
50       # create and use a timestamp for the cache key: GH Actions will never update a cache
51       # only use an existing cache item or create a new one. To use an existing cache *and*
52       # push back the the updated cache after build, we use a always new cache key (to force
53       # the creation of the cache item at the end) in combination with "restore-keys" as fallback
54       - name: Prepare ccache timestamp
55         id: ccache_cache_timestamp
56         run: echo "timestamp=$(date +%Y-%m-%d-%H-%M)" >> $GITHUB_OUTPUT
58       - name: Configure ccache
59         uses: actions/cache@v4
60         with:
61           path: ${{ env.CCACHE_DIR }}
62           key: ${{ runner.os }}-${{ github.job }}-ccache-${{ steps.ccache_cache_timestamp.outputs.timestamp }}
63           restore-keys: ${{ runner.os }}-${{ github.job }}-ccache-
65       - name: Show environment
66         run: env | sort
67         if: ${{ env.DEBUG == '1' }}
69       - name: Install dependencies
70         run: |
71           sudo apt-get update -qq
72           sudo apt-get install --assume-yes --no-install-recommends \
73             ccache \
74             gettext autopoint \
75             libtool \
76             libgtk-3-dev \
77             doxygen \
78             python3-docutils \
79             python3-lxml \
80             rst2pdf
82       - name: Configure
83         run: |
84           NOCONFIGURE=1 ./autogen.sh
85           mkdir _build
86           cd _build
87           { ../configure $CONFIGURE_FLAGS || { cat config.log; exit 1; } ; }
89       - name: Build
90         run: |
91           cd _build
92           make -j ${{ env.JOBS }}
94       - name: Run Tests
95         run: |
96           cd _build
97           make -j ${{ env.JOBS }} check
99       - name: Run distcheck
100         run: |
101           cd _build
102           make -j ${{ env.JOBS }} distcheck DISTCHECK_CONFIGURE_FLAGS="$CONFIGURE_FLAGS";
104       - name: ccache statistics
105         run: ccache --show-stats
106         if: ${{ env.DEBUG == '1' }}
108   linux-meson:
109     name: Linux Meson Build
110     runs-on: ubuntu-20.04
112     strategy:
113       fail-fast: false
115     env:
116       CC: ccache gcc
117       CXX: ccache g++
119     steps:
120       - uses: actions/checkout@v4
122       # create and use a timestamp for the cache key: GH Actions will never update a cache
123       # only use an existing cache item or create a new one. To use an existing cache *and*
124       # push back the the updated cache after build, we use a always new cache key (to force
125       # the creation of the cache item at the end) in combination with "restore-keys" as fallback
126       - name: Prepare ccache timestamp
127         id: ccache_cache_timestamp
128         run: echo "timestamp=$(date +%Y-%m-%d-%H-%M)" >> $GITHUB_OUTPUT
130       - name: Configure ccache
131         uses: actions/cache@v4
132         with:
133           path: ${{ env.CCACHE_DIR }}
134           key: ${{ runner.os }}-${{ github.job }}-ccache-${{ steps.ccache_cache_timestamp.outputs.timestamp }}
135           restore-keys: ${{ runner.os }}-${{ github.job }}-ccache-
137       - name: Show environment
138         run: env | sort
139         if: ${{ env.DEBUG == '1' }}
141       - name: Install dependencies
142         run: |
143           sudo apt-get update -qq
144           sudo apt-get install --assume-yes --no-install-recommends \
145             ccache \
146             gettext autopoint \
147             libtool \
148             libgtk-3-dev \
149             doxygen \
150             python3-docutils \
151             python3-lxml \
152             rst2pdf \
153             meson
155       - name: Configuration
156         run: |
157           meson _build
159       - name: Build
160         run: |
161           ninja -C _build
163       - name: Run Tests
164         run: |
165           ninja -C _build test
167       # distcheck not applicable, meson exports the source tree per git-archive
169       - name: ccache statistics
170         run: ccache --show-stats
171         if: ${{ env.DEBUG == '1' }}
173   mingw64:
174     name: Mingw-w64 Build (Windows)
175     runs-on: ubuntu-20.04
177     env:
178       INFRASTRUCTURE_PATH:      ${{ github.workspace }}/.infrastructure
179       BUILDER_PATH:             ${{ github.workspace }}/.infrastructure/builders
180       DOCKER_REGISTRY:          "ghcr.io"
181       DOCKER_IMAGE_NAME:        "geany-mingw64-ci"
182       DOCKER_IMAGE_TAG:         "ghcr.io/geany/geany-mingw64-ci:latest"
184     steps:
185       - name: Checkout Geany
186         uses: actions/checkout@v4
188       - name: Checkout Build Scripts
189         uses: actions/checkout@v4
190         with:
191           ref: master
192           repository: geany/infrastructure
193           path: ${{ env.INFRASTRUCTURE_PATH }}
194           token: ${{ github.token }}
196       - uses: jwalton/gh-find-current-pr@v1
197         id: find_pull_request
198         with:
199           state: open
201       - name: Define environment variables
202         run: |
203           echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
204           echo "GITHUB_PULL_REQUEST=${GITHUB_PULL_REQUEST}" >> $GITHUB_ENV
205           echo "GITHUB_PULL_REQUEST_OR_REF=${GITHUB_PULL_REQUEST:-${{ github.ref_name }}}" | tr '/' '-' >> $GITHUB_ENV
206         env:
207           GITHUB_PULL_REQUEST: ${{ steps.find_pull_request.outputs.pr }}
209       - name: Show Environment
210         if: ${{ env.DEBUG == '1' }}
211         run: |
212             env | sort
214       - name: Log in to the Container registry
215         uses: docker/login-action@v3
216         with:
217           registry: ${{ env.DOCKER_REGISTRY }}
218           username: ${{ github.actor }}
219           password: ${{ secrets.GITHUB_TOKEN }}
221       - name: Pull Or Build Docker Image
222         working-directory: ${{ env.BUILDER_PATH }}
223         run: |
224           docker_image_created=
225           docker pull ${{ env.DOCKER_IMAGE_TAG }} || true
226           if $(docker image inspect ${{ env.DOCKER_IMAGE_TAG }} --format="ignored" >/dev/null 2>&1); then
227               docker tag ${{ env.DOCKER_IMAGE_TAG }} ${{ env.DOCKER_IMAGE_NAME }}
228               docker_image_created=$(docker image inspect ${{ env.DOCKER_IMAGE_NAME }} --format='{{ index .Config.Labels "org.opencontainers.image.created" }}')
229               echo "Docker image built on: ${docker_image_created}"
230           fi
232           bash start_build.sh --log-to-stdout --mingw64 --rebuild-images
233           docker_image_created_new=$(docker image inspect ${{ env.DOCKER_IMAGE_NAME }} --format='{{ index .Config.Labels "org.opencontainers.image.created" }}')
234           # tag the image
235           if [ "${docker_image_created}" != "${docker_image_created_new}" ]; then
236               docker tag ${{ env.DOCKER_IMAGE_NAME }} ${{ env.DOCKER_IMAGE_TAG }}
237           fi
239       - name: Build Geany
240         if: steps.geany_cache.outputs.cache-hit != 'true'
241         working-directory: ${{ env.BUILDER_PATH }}
242         run: |
243             bash start_build.sh --log-to-stdout --mingw64 --geany --geany-source "${{ github.workspace }}"
245       - name: Archive Geany Installer
246         uses: actions/upload-artifact@v4
247         with:
248           name: geany-installer-ci-${{ env.SHORT_SHA }}-pr${{ env.GITHUB_PULL_REQUEST_OR_REF }}
249           retention-days: 30
250           path: |
251             ${{ env.BUILDER_PATH }}/output/mingw64/geany-*.exe
252             ${{ env.BUILDER_PATH }}/output/mingw64/geany-*.zip