-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
94 lines (89 loc) · 2.97 KB
/
.gitlab-ci.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
stages:
- sync
- test
- build
test_pyfsense_client:
stage: test
image: python:3.11
tags:
- python
only:
- master
before_script:
- python --version
- pip --version
# This is needed to run tests
- touch src/pyfsense_client/.env
script:
- pip install -r requirements/requirements_dev.txt
# Install pyfsense_client in editable mode
- pip install -e .
# Run all tests
- pytest tests/unit/
build_and_publish:
image: python:3.11
stage: build
tags:
- python
rules:
# Build on master branch and tags
- if: '$CI_COMMIT_REF_NAME == "master" || $CI_COMMIT_TAG'
when: on_success
exists:
- src/pyfsense_client/__init__.py
before_script:
- apt-get update && apt-get install -y jq
# Get the project version from PyPI
- export PYPI_PROJECT_VERSION=$(curl $UNOBTAIN_INDEX_URL/pyfsense-client/json | jq -r '.info.version')
- echo "PyPI project version - $PYPI_PROJECT_VERSION"
# Get the project version from the project source code
- export PROJECT_VERSION=$(grep "__version__" src/pyfsense_client/__init__.py | awk -F "[\"']" '{print $2}')
- echo "Project version - $PROJECT_VERSION"
- |
if [ -z "${PROJECT_VERSION}" ]; then
echo "ERROR: PROJECT_VERSION is empty"
exit 1
fi
# We should build the project if the source version is different from the PyPI project version
- export SHOULD_BUILD=$([ "$PYPI_PROJECT_VERSION" == "$PROJECT_VERSION" ] && echo "false" || echo "true")
- echo "Should build - $SHOULD_BUILD"
script:
# Don't build if the project version is the same as the PyPI project version
- |
if [ "$SHOULD_BUILD" != "true" ]; then
echo "Skipping build as SHOULD_BUILD is not true"
exit 0
fi
- |
if [[ -n "$CI_COMMIT_TAG" ]]; then
echo "Building on tag - $CI_COMMIT_TAG"
# Check that the project version matches the commit tag
if [ "$CI_COMMIT_TAG" != "v$PROJECT_VERSION" ]; then exit 1; fi
else
echo "Building on branch - $CI_COMMIT_REF_NAME"
fi
- pip install hatch
- hatch build
- hatch publish --repo $PYPI_REPO_URL --user $PYPI_REPO_USER --auth $PYPI_REPO_AUTH
# Push a public copy of this repo up to GitHub
sync_public_repo:
stage: sync
image: python:3.12-alpine
before_script:
- apk add --no-cache git openssh-client bash
- wget https://github.com/newren/git-filter-repo/raw/main/git-filter-repo -O /usr/local/bin/git-filter-repo
- chmod +x /usr/local/bin/git-filter-repo
- eval $(ssh-agent -s)
- echo "$GITHUB_SSH_PUSH_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan github.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email "[email protected]"
- git config --global user.name "Devin Barry"
script:
- bash ./scripts/sync_public_repo.sh
only:
- master
variables:
FORCE_SYNC: ${FORCE_SYNC:-"false"}