Skip to content

Commit 961575f

Browse files
diewdurbin
andauthored
GitHub Actions (#9083)
* GitHub Actions * Use GITHUB_BASE_REF instead * Add conditionals * Add missing check for CI * Split linting, and lint in container * Guard against bad diff * Why not do reformat as well while we're at it Co-authored-by: Ee W. Durbin III <[email protected]>
1 parent 3a47665 commit 961575f

File tree

7 files changed

+172
-22
lines changed

7 files changed

+172
-22
lines changed

.github/workflows/ci.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: CI
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
strategy:
6+
matrix:
7+
include:
8+
- name: Tests
9+
command: bin/tests --postgresql-host localhost
10+
needs-python: ${{ true }}
11+
needs-node: ${{ false }}
12+
- name: Lint
13+
command: bin/lint
14+
needs-python: ${{ true }}
15+
needs-node: ${{ false }}
16+
- name: Documentation
17+
command: make docs BINDIR="$(dirname $(which python))"
18+
needs-python: ${{ true }}
19+
needs-node: ${{ false }}
20+
- name: Dependencies
21+
command: make github-actions-deps BINDIR="$(dirname $(which python))"
22+
needs-python: ${{ true }}
23+
needs-node: ${{ false }}
24+
- name: Licenses
25+
command: make licenses BINDIR="$(dirname $(which python))"
26+
needs-python: ${{ true }}
27+
needs-node: ${{ false }}
28+
- name: Translations
29+
command: make translations BINDIR="$(dirname $(which python))"
30+
needs-python: ${{ true }}
31+
needs-node: ${{ false }}
32+
- name: Static Tests
33+
command: bin/static_tests
34+
needs-python: ${{ false }}
35+
needs-node: ${{ true }}
36+
- name: Static Lint
37+
command: bin/static_lint
38+
needs-python: ${{ false }}
39+
needs-node: ${{ true }}
40+
- name: Static Pipeline
41+
command: bin/static_pipeline
42+
needs-python: ${{ false }}
43+
needs-node: ${{ true }}
44+
runs-on: ubuntu-latest
45+
services:
46+
postgres:
47+
image: postgres:10.1
48+
ports:
49+
- 5432:5432
50+
name: ${{ matrix.name }}
51+
steps:
52+
- name: Check out repository
53+
uses: actions/checkout@v2
54+
- name: Install platform dependencies
55+
run: sudo apt -y install libcurl4-openssl-dev libssl-dev pkg-config
56+
- uses: actions/setup-python@v2
57+
if: ${{ matrix.needs-python }}
58+
with:
59+
python-version: 3.8.2
60+
- name: Cache Python dependencies
61+
if: ${{ matrix.needs-python }}
62+
uses: actions/cache@v2
63+
env:
64+
cache-name: warehouse-cache-pip
65+
with:
66+
path: ~/.cache/pip
67+
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('requirements.txt', 'requirements/*.txt') }}
68+
restore-keys: |
69+
${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-
70+
${{ runner.os }}-${{ github.job }}-
71+
${{ runner.os }}-
72+
- name: Install Python dependencies
73+
if: ${{ matrix.needs-python }}
74+
run: |
75+
pip install -U pip setuptools wheel
76+
pip install -r requirements.txt
77+
pip install -r requirements/dev.txt
78+
- uses: actions/setup-node@v2
79+
if: ${{ matrix.needs-node }}
80+
with:
81+
node-version: 14.4.0
82+
- name: Cache Node dependencies
83+
if: ${{ matrix.needs-node }}
84+
uses: actions/cache@v2
85+
env:
86+
cache-name: warehouse-cache-npm
87+
with:
88+
path: ~/.npm
89+
key: ${{ runner.os }}-build-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
90+
restore-keys: |
91+
${{ runner.os }}-build-${{ github.job }}-${{ env.cache-name }}-
92+
${{ runner.os }}-build-${{ github.job }}-
93+
${{ runner.os }}-build-
94+
${{ runner.os }}-
95+
- name: Install Node dependencies
96+
if: ${{ matrix.needs-node }}
97+
run: npm ci
98+
- name: Run ${{ matrix.name }}
99+
run: ${{ matrix.command }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ RUN set -x \
111111
install --no-binary hiredis \
112112
-r /tmp/requirements/deploy.txt \
113113
-r /tmp/requirements/main.txt \
114-
$(if [ "$DEVEL" = "yes" ]; then echo '-r /tmp/requirements/tests.txt'; fi) \
114+
$(if [ "$DEVEL" = "yes" ]; then echo '-r /tmp/requirements/tests.txt -r /tmp/requirements/lint.txt'; fi) \
115115
$(if [ "$THEME_REPO" != "" ]; then echo '-r /tmp/requirements/theme.txt'; fi) \
116116
&& find /opt/warehouse -name '*.pyc' -delete
117117

Makefile

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ BINDIR = $(PWD)/.state/env/bin
22
TRAVIS := $(shell echo "$${TRAVIS:-false}")
33
PR := $(shell echo "$${TRAVIS_PULL_REQUEST:-false}")
44
BRANCH := $(shell echo "$${TRAVIS_BRANCH:-master}")
5+
GITHUB_ACTIONS := $(shell echo "$${GITHUB_ACTIONS:-false}")
6+
GITHUB_BASE_REF := $(shell echo "$${GITHUB_BASE_REF:-false}")
57
DB := example
68
IPYTHON := no
79
LOCALES := $(shell .state/env/bin/python -c "from warehouse.i18n import KNOWN_LOCALES; print(' '.join(set(KNOWN_LOCALES)-{'en'}))")
@@ -99,26 +101,15 @@ static_pipeline: .state/docker-build
99101
PATH="/opt/warehouse/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
100102
bin/static_pipeline $(T) $(TESTARGS)
101103

102-
reformat: .state/env/pyvenv.cfg
103-
$(BINDIR)/isort *.py warehouse/ tests/
104-
$(BINDIR)/black *.py warehouse/ tests/
105-
106-
lint: .state/env/pyvenv.cfg
107-
$(BINDIR)/flake8 .
108-
$(BINDIR)/black --check *.py warehouse/ tests/
109-
$(BINDIR)/isort --check *.py warehouse/ tests/
110-
$(BINDIR)/doc8 --allow-long-titles README.rst CONTRIBUTING.rst docs/ --ignore-path docs/_build/
111-
$(BINDIR)/curlylint ./warehouse/templates
112-
113-
ifneq ($(TRAVIS), false)
114-
# We're on Travis, so we can lint static files locally
115-
./node_modules/.bin/eslint 'warehouse/static/js/**' '**.js' 'tests/frontend/**' --ignore-pattern 'warehouse/static/js/vendor/**'
116-
./node_modules/.bin/sass-lint --verbose
117-
else
118-
# We're not on Travis, so we should lint static files inside the static container
119-
docker-compose run --rm static ./node_modules/.bin/eslint 'warehouse/static/js/**' '**.js' 'tests/frontend/**' --ignore-pattern 'warehouse/static/js/vendor/**'
120-
docker-compose run --rm static ./node_modules/.bin/sass-lint --verbose
121-
endif
104+
reformat: .state/docker-build
105+
docker-compose run --rm web env -i ENCODING="C.UTF-8" \
106+
PATH="/opt/warehouse/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
107+
bin/reformat
108+
109+
lint: .state/docker-build
110+
docker-compose run --rm web env -i ENCODING="C.UTF-8" \
111+
PATH="/opt/warehouse/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
112+
bin/lint && bin/static_lint
122113

123114
docs: .state/env/pyvenv.cfg
124115
$(MAKE) -C docs/ doctest SPHINXOPTS="-W" SPHINXBUILD="$(BINDIR)/sphinx-build"
@@ -139,9 +130,21 @@ deps: .state/env/pyvenv.cfg
139130
rm -r $(TMPDIR)
140131
$(BINDIR)/pip check
141132

133+
github-actions-deps:
134+
ifneq ($(GITHUB_BASE_REF), false)
135+
git fetch origin $(GITHUB_BASE_REF):refs/remotes/origin/$(GITHUB_BASE_REF)
136+
# Check that the following diff will exit with 0 or 1
137+
git diff --name-only FETCH_HEAD || test $? -le 1 || exit 1
138+
# Make the dependencies if any changed files are requirements files, otherwise exit
139+
git diff --name-only FETCH_HEAD | grep '^requirements/' || exit 0 && $(MAKE) deps
140+
endif
141+
142142
travis-deps:
143143
ifneq ($(PR), false)
144144
git fetch origin $(BRANCH):refs/remotes/origin/$(BRANCH)
145+
# Check that the following diff will exit with 0 or 1
146+
git diff --name-only $(BRANCH) || test $? -le 1 || exit 1
147+
# Make the dependencies if any changed files are requirements files, otherwise exit
145148
git diff --name-only $(BRANCH) | grep '^requirements/' || exit 0 && $(MAKE) deps
146149
endif
147150

@@ -200,7 +203,7 @@ build-mos: compile-pot
200203
done
201204

202205
translations: compile-pot
203-
ifneq ($(TRAVIS), false)
206+
ifneq ($(filter false,$(TRAVIS) $(GITHUB_ACTIONS)),)
204207
git diff --quiet ./warehouse/locale/messages.pot || (echo "There are outstanding translations, run 'make translations' and commit the changes."; exit 1)
205208
else
206209
endif

bin/lint

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Click requires us to ensure we have a well configured environment to run
5+
# our click commands. So we'll set our environment to ensure our locale is
6+
# correct.
7+
export LC_ALL="${ENCODING:-en_US.UTF-8}"
8+
export LANG="${ENCODING:-en_US.UTF-8}"
9+
10+
COMMAND_ARGS=$@
11+
12+
# Print all the followng commands
13+
set -x
14+
15+
# Actually run our tests.
16+
python -m flake8 .
17+
python -m black --check *.py warehouse/ tests/
18+
python -m isort --check *.py warehouse/ tests/
19+
python -m doc8 --allow-long-titles README.rst CONTRIBUTING.rst docs/ --ignore-path docs/_build/
20+
python -m curlylint ./warehouse/templates

bin/reformat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Click requires us to ensure we have a well configured environment to run
5+
# our click commands. So we'll set our environment to ensure our locale is
6+
# correct.
7+
export LC_ALL="${ENCODING:-en_US.UTF-8}"
8+
export LANG="${ENCODING:-en_US.UTF-8}"
9+
10+
# Print all the followng commands
11+
set -x
12+
13+
python -m isort *.py warehouse/ tests/
14+
python -m black *.py warehouse/ tests/

bin/static_lint

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
set -x
4+
5+
# Click requires us to ensure we have a well configured environment to run
6+
# our click commands. So we'll set our environment to ensure our locale is
7+
# correct.
8+
export LC_ALL="${ENCODING:-en_US.UTF-8}"
9+
export LANG="${ENCODING:-en_US.UTF-8}"
10+
11+
# Actually run our tests.
12+
./node_modules/.bin/eslint 'warehouse/static/js/**' '**.js' 'tests/frontend/**' --ignore-pattern 'warehouse/static/js/vendor/**'
13+
./node_modules/.bin/sass-lint --verbose

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ services:
8585
- ./htmlcov:/opt/warehouse/src/htmlcov:z
8686
- .coveragerc:/opt/warehouse/src/.coveragerc:z
8787
- packages:/var/opt/warehouse/packages
88+
- ./bin:/opt/warehouse/src/bin:z
8889
ports:
8990
- "80:8000"
9091

0 commit comments

Comments
 (0)