11name : CI
22on :
33 workflow_dispatch :
4+ inputs :
5+ push-docker-image-to-harbor :
6+ description : " Push Docker Image to Harbor"
7+ type : boolean
8+ default : false
49 pull_request :
510 push :
611 branches :
3540 python -m pip install .[code-analysis]
3641 python -m pip install -r requirements.txt
3742
43+ - name : Run black
44+ run : black --check --line-length 120 ldap_jwt_auth test
45+
3846 - name : Run pylint
3947 run : pylint ldap_jwt_auth
4048
@@ -45,57 +53,56 @@ jobs:
4553 - name : Checkout repository
4654 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4755
48- - name : Install python-ldap system dependencies
49- run : |
50- sudo apt-get update
51- sudo apt-get install -y libsasl2-dev python3-dev libldap2-dev libssl-dev
52-
53- - name : Set up Python
54- uses : actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
55- with :
56- python-version : " 3.12"
57- cache : " pip"
58-
59- - name : Install dependencies
60- run : |
61- python -m pip install --upgrade pip
62- python -m pip install .[test]
63- python -m pip install -r requirements.txt
64-
6556 - name : Create logging configuration file
66- run : cp ldap_jwt_auth/ logging.example.ini ldap_jwt_auth/ logging.ini
57+ run : cp logging.example.ini logging.ini
6758
6859 - name : Run unit tests
69- run : pytest -c test/pytest.ini test/unit/ --cov
60+ run : |
61+ docker build --file Dockerfile --target test --tag ldap-jwt-auth:test .
62+ docker run \
63+ --name ldap-jwt-auth \
64+ --volume ./logging.ini:/app/logging.ini \
65+ ldap-jwt-auth:test \
66+ pytest --config-file test/pytest.ini --cov ldap_jwt_auth --cov-report xml test/unit -v
67+ docker cp ldap-jwt-auth:/app/coverage.xml coverage.xml
68+
69+ - name : Upload coverage reports to Codecov
70+ if : success()
71+ uses : codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
72+ with :
73+ token : ${{ secrets.CODECOV_TOKEN }}
7074
7175 docker :
72- # This job triggers only if all the other jobs succeed. It builds the Docker image and if successful,
73- # it pushes it to Harbor.
76+ # This job triggers only if all the other jobs succeed. It builds the Docker image
77+ # and if run manually from Github Actions, it pushes to Harbor.
7478 needs : [linting, unit-tests]
7579 name : Docker
7680 runs-on : ubuntu-latest
81+ env :
82+ PUSH_DOCKER_IMAGE_TO_HARBOR : ${{ inputs.push-docker-image-to-harbor != null && inputs.push-docker-image-to-harbor || 'false' }}
7783 steps :
7884 - name : Check out repo
7985 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
8086
87+ - name : Extract metadata (tags, labels) for Docker
88+ id : meta
89+ uses : docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
90+ with :
91+ images : ${{ vars.HARBOR_URL }}/auth-api
92+
8193 - name : Login to Harbor
94+ if : ${{ fromJSON(env.PUSH_DOCKER_IMAGE_TO_HARBOR) }}
8295 uses : docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
8396 with :
84- registry : ${{ secrets .HARBOR_URL }}
97+ registry : ${{ vars .HARBOR_URL }}
8598 username : ${{ secrets.HARBOR_USERNAME }}
8699 password : ${{ secrets.HARBOR_TOKEN }}
87100
88- - name : Extract metadata (tags, labels) for Docker
89- id : meta
90- uses : docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
91- with :
92- images : ${{ secrets.HARBOR_URL }}/auth-api
93-
94- - name : Build and push Docker image to Harbor
95- uses : docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
101+ - name : ${{ fromJSON(env.PUSH_DOCKER_IMAGE_TO_HARBOR) && 'Build and push Docker image to Harbor' || 'Build Docker image' }}
102+ uses : docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
96103 with :
97104 context : .
98- file : ./Dockerfile.prod
99- push : true
105+ push : ${{ fromJSON(env.PUSH_DOCKER_IMAGE_TO_HARBOR) }}
100106 tags : ${{ steps.meta.outputs.tags }}
101107 labels : ${{ steps.meta.outputs.labels }}
108+ target : prod
0 commit comments