-
Notifications
You must be signed in to change notification settings - Fork 66
130 lines (111 loc) · 4.23 KB
/
build-and-test.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Run tests against developer push
# Runs jobs on linux and windows to maintain compatibility.
# The main repo is checked out into a sub-directory because an optional
# second repo may be checked out for testing.
# Optional GitHub secrets
# See ci-helper.test.ts for information on the following
# GGG_IMAP_HOST = <email_imap_hostname>
# GGG_SMTP_USER = <email_userid>
# GGG_SMTP_PASS = <email_password>
# GGG_SMTP_HOST = <email_hostname>
# GGG_SMTP_OPTS = <email_smtp_options> This is a json object.
# See github-glue.test.ts for information on the following
# GGG_TOKEN = token to access the test repo
# GGG_REPOSITORY = name of test repo to update in tests. Tests will
# open a PR, create comments, etc. This can be a private or public
# repo.
name: Build & run tests
on:
push:
branches-ignore:
- dependabot/**
pull_request:
jobs:
build-test:
name: Node v${{ matrix.node-version }} on ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [20.x]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
# job level env vars used for a couple of steps
env:
GGG_TOKEN: ${{ secrets.GGG_TOKEN }}
GGG_REPOSITORY: ${{ secrets.GGG_REPOSITORY }}
GGG_SMTP_USER: ${{ secrets.GGG_SMTP_USER }}
GGG_SMTP_PASS: ${{ secrets.GGG_SMTP_PASS }}
GGG_SMTP_HOST: ${{ secrets.GGG_SMTP_HOST }}
GGG_IMAP_HOST: ${{ secrets.GGG_IMAP_HOST }}
steps:
# Check out repo under sub-dir so other repo can be checked out
- uses: actions/checkout@v4
with:
path: gitgitgadget
- name: Set git test repo config
shell: bash
run: |
if [ -n "$GGG_TOKEN" ] && [ -n "$GGG_REPOSITORY" ];
then
echo "GGG_REPO='gitgitgadget.CIGitHubTestUser=$GITHUB_REPOSITORY_OWNER' 'gitgitgadget.$GITHUB_REPOSITORY_OWNER.githubrepo=$GGG_REPOSITORY' 'gitgitgadget.$GITHUB_REPOSITORY_OWNER.githubtoken=$GGG_TOKEN'" >> $GITHUB_ENV
else
echo "::error::Both GGG_TOKEN and GGG_REPOSITORY secrets must be set"
exit 1
fi
if: env.GGG_TOKEN || env.GGG_REPOSITORY
- name: Set smtp config
env:
GGG_SMTP_OPTS: ${{ secrets.GGG_SMTP_OPTS }}
shell: bash
run: |
if [ -n "$GGG_SMTP_USER" ] && [ -n "$GGG_SMTP_PASS" ] && [ -n "$GGG_SMTP_HOST" ] && [ -n "$GGG_IMAP_HOST" ];
then
m="'gitgitgadget.cismtpuser=$GGG_SMTP_USER' 'gitgitgadget.cismtppass=$GGG_SMTP_PASS' 'gitgitgadget.cismtphost=$GGG_SMTP_HOST' 'gitgitgadget.ciimaphost=$GGG_IMAP_HOST'";
if [ -n "$GGG_SMTP_OPTS" ];
then
m+=" 'gitgitgadget.cismtpopts=$GGG_SMTP_OPTS'"
fi
# trailing space is required if repo set
if [ -n "$GGG_REPO" ];
then
m+=" "
fi
echo "GGG_SMTP=$m" >> $GITHUB_ENV
else
echo "::error::All of GGG_SMTP_USER, GGG_SMTP_PASS and GGG_SMTP_HOST secrets must be set"
exit 1
fi
if: env.GGG_SMTP_USER || env.GGG_SMTP_PASS || env.GGG_SMTP_HOST
# Check out github-glue.test.ts repo if configured for it
- uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/${{ env.GGG_REPOSITORY }}
token: ${{ env.GGG_TOKEN }}
path: ${{ env.GGG_REPOSITORY }}
if: env.GGG_TOKEN
- uses: actions/setup-node@v4
with:
node-version: '${{ matrix.node-version }}'
- name: Install packages
run: npm ci
working-directory: gitgitgadget
- name: Run linter
run: npm run lint
working-directory: gitgitgadget
- name: Run build
run: npm run build
working-directory: gitgitgadget
- name: Run tests
env:
GIT_CONFIG_PARAMETERS: ${{ env.GGG_SMTP }}${{ env.GGG_REPO }}
run: npm run test
working-directory: gitgitgadget
- name: Clean up two day old branches and PRs
uses: actions/github-script@v7
id: clean-up
with:
github-token: ${{ env.GGG_TOKEN }}
script: |
const exports = require(`${process.env.GITHUB_WORKSPACE}/gitgitgadget/build/lib/delete-ci-test-branches.js`)
await exports.deleteBranches(github, process.env.GITHUB_REPOSITORY_OWNER, process.env.GGG_REPOSITORY);
if: env.GGG_REPOSITORY