Skip to content

Commit f83ae03

Browse files
committed
Add tests for mainline and cache behaviour
1 parent 64df2b9 commit f83ae03

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

.github/workflows/build-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515
pv:
1616
description: The $PV value from the cygport file
1717
value: ${{ jobs.build-test.outputs.pv }}
18+
cache-found:
19+
description: Whether an existing build cache was found and used
20+
value: ${{ jobs.build-test.outputs.cache-found }}
1821

1922
jobs:
2023
build-test:
@@ -24,6 +27,7 @@ jobs:
2427
CYGPORT_FILE: ${{ inputs.cygport_file }}
2528
outputs:
2629
pv: ${{ steps.data.outputs.pv }}
30+
cache-found: ${{ steps.build-cache.outputs.cache-hit == 'true' }}
2731
steps:
2832

2933
- name: Configure Git for Windows' core.autocrlf

.github/workflows/workflow-tests.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Test workflows
2+
on: [push, pull_request]
3+
4+
# Avoid multiple caching tests stomping over each other
5+
concurrency: mainline-cache-${{ github.sha }}
6+
7+
jobs:
8+
# We need to start with a clean slate for this SHA, so we can distinguish
9+
# between caches created in different ref contexts.
10+
clear-caches:
11+
name: Clear any existing caches
12+
permissions:
13+
actions: write
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Clear existing caches for this commit
17+
uses: actions/github-script@v6
18+
with:
19+
script: |
20+
try {
21+
const response = await github.rest.actions.deleteActionsCacheByKey({
22+
owner: context.repo.owner,
23+
repo: context.repo.repo,
24+
key: `mainline-build-${context.sha}`
25+
});
26+
core.info(`Deleted ${response.data.total_count} caches`);
27+
if (core.isDebug()) {
28+
for (const cache of response.data.actions_caches) {
29+
core.debug(`Deleted cache ID ${cache.id}, ref ${cache.ref}, key ${cache.key}, version ${cache.version}`);
30+
}
31+
}
32+
} catch(e) {
33+
if (e.response.status == 404) {
34+
core.info('No caches to delete');
35+
return;
36+
}
37+
throw(e); // Not the error we were looking for
38+
}
39+
40+
mainline:
41+
name: Basic mainline test
42+
needs: clear-caches
43+
uses: ./.github/workflows/build-test.yml
44+
with:
45+
cygport_file: t/mainline.cygport
46+
47+
ensure-build-cache:
48+
name: Check there's a current build cache
49+
needs: mainline
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Check number of caches for the mainline build
53+
id: check
54+
uses: actions/github-script@v6
55+
with:
56+
script: |
57+
const response = await github.rest.actions.getActionsCacheList({
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
key: 'mainline-build-' + context.sha
61+
});
62+
core.info(`Found ${response.data.total_count} caches`);
63+
if (response.data.total_count != 1) {
64+
core.setFailed(`Expected one cache entry, found ${response.data.total_count}.`);
65+
if (response.data.total_count > 0) {
66+
core.startGroup('Cache list');
67+
response.data.actions_caches.forEach(cache =>
68+
core.info(`cache id: ${cache.id}, ref: ${cache.ref}, key: ${cache.key}, version: ${cache.version}`));
69+
core.endGroup();
70+
}
71+
}
72+
73+
mainline-use-cache:
74+
name: Check a build won't create a new cache unnecessarily
75+
needs: mainline
76+
uses: ./.github/workflows/build-test.yml
77+
with:
78+
cygport_file: t/mainline.cygport
79+
80+
ensure-cache-used:
81+
name: Check the build did use the extant cache
82+
needs: mainline-use-cache
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Error if cache unused
86+
if: needs.mainline-use-cache.outputs.cache-found != 'true'
87+
run: |
88+
echo '::error title=Cache not used::Cache reportedly not used for rebuild'
89+
exit 1

t/mainline.cygport

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Most basic test cygport file I can manage
2+
NAME=mainline
3+
VERSION=1
4+
RELEASE=1
5+
CATEGORY=Test
6+
SUMMARY='Test package'
7+
HOMEPAGE=
8+
LICENSE=
9+
10+
src_compile () {
11+
cd "$B"
12+
{
13+
echo '#!/usr/bin/env sh'
14+
echo "echo 'Hello, world!'"
15+
} >helloworld
16+
}
17+
18+
src_install () {
19+
cd "$B"
20+
dobin helloworld
21+
}
22+
23+
# vim: set ft=bash noexpandtab tabstop=8 listchars=tab\:\ \ ,trail\:-,lead\:- :

0 commit comments

Comments
 (0)