-
Notifications
You must be signed in to change notification settings - Fork 54
116 lines (97 loc) · 4.06 KB
/
tests.yml
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
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Build, test, and report coverage of recent files
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
# Sets the ENV `MIX_ENV` to `test` for running tests
env:
MIX_ENV: test
ELIXIR_VER: '1.16.3'
OTP_VER: '26.2.5.2'
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
name: Build and test
# Set up a Postgres DB service. By default, Phoenix applications
# use Postgres. This creates a database for running tests.
# Additional services can be defined here if required.
services:
db:
image: postgres:15
ports: ['5432:5432']
env:
POSTGRES_DB: teiserver_test
POSTGRES_USER: teiserver_test
POSTGRES_PASSWORD: 123456789
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
# Step: Setup Elixir + Erlang image as the base.
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.OTP_VER }}
elixir-version: ${{ env.ELIXIR_VER }}
# Step: Check out the code.
- name: Checkout code
uses: actions/checkout@v4
# Step: Define how to cache deps. Restores existing cache if present.
- name: Cache deps
id: cache-deps
uses: actions/cache@v4
env:
cache-name: cache-elixir-deps
with:
path: deps
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
# Step: Define how to cache the `_build` directory. After the first run,
# this speeds up tests runs a lot. This includes not re-compiling our
# project's downloaded deps every run.
- name: Cache compiled build
id: cache-build
uses: actions/cache@v4
env:
cache-name: cache-compiled-build
with:
path: _build
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
# Step: Download project dependencies. If unchanged, uses
# the cached version.
- name: Install dependencies
run: mix deps.get
# Step: Compile the current project. If unchanged, uses
# the cached version.
- name: Install dependencies
run: mix compile
- name: create cover folder if not exists, to cache coverage reporting results
run: mkdir -p ./cover/
- name: emit hint on where to update minimum test coverage
run: echo "to update minimum test coverage requirements, edit coveralls.json"
- name: Run tests, failing loudly on error, emitting coverage to file for use when reporting test coverage in later proposed step
run: set -eo pipefail; mix test --exclude needs_attention --cover | tee ./cover/test_coverage_by_file.txt
# run git fetch --shallow-since far enough back to be confident we'll see some merge commits to the master branch
# (running off the end of a shallow commit history causes git log to believe every file has changed, somehow)
- name: git fetch more than just the most recent commit
run: git fetch --shallow-since="6 months"
- name: generate list of files changed in the last month
run: git --no-pager log --name-only --oneline --since='1 month ago' | tee ./cover/files_changed_in_last_month.txt
- name: echo coverage header to the files_changed_in_last_month file to assist in reporting
run: echo "LINES RELEVANT MISSED" | tee -a ./cover/files_changed_in_last_month.txt
- name: use grep to create test coverage report only on recently changed files, sorted by coverage percent
run: grep -F -f ./cover/files_changed_in_last_month.txt ./cover/test_coverage_by_file.txt | grep -A999 "LINES RELEVANT MISSED" | sort -g