-
Notifications
You must be signed in to change notification settings - Fork 35
133 lines (129 loc) · 5.6 KB
/
merge_pr.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
131
132
133
name: "PR merge workflow"
on:
push:
branches:
- main
jobs:
apply-autopep8:
name: Autopep8 auto-format by a bot
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ vars.PYTHON_VERSION }}
- name: Apply isort
id: isort-step
# default configuration use --check-only and --diff instead of --in-place options.
uses: isort/isort-action@master
with:
configuration: --only-modified
- name: autopep8 check and fix
id: autopep8
uses: peter-evans/autopep8@v2
with:
args: --exit-code --recursive --in-place --aggressive --aggressive .
- name: Detect changes by isort
uses: tj-actions/verify-changed-files@v18
id: verify-isort-update
with:
files: |
tests/
sinergym/
examples/
*.py
- name: Commit format changes
if: steps.autopep8.outputs.exit-code == 2 || steps.verify-isort-update.outputs.files_changed == 'true'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Automated format fixes (autopep8 + isort)
apply-documentation:
name: Documentation compilation update by bot
needs: [apply-autopep8]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ vars.PYTHON_VERSION }}
- name: Verify documentation update
uses: dorny/paths-filter@v3
id: verify-documentation-update
with:
filters: |
doc:
- 'docs/source/**'
- name: Build the latest Docker image
if: steps.verify-documentation-update.outputs.doc == 'true'
run: docker build . --file Dockerfile --build-arg SINERGYM_EXTRAS=[extras] --tag pushmain/sinergym:latest
- name: Give permissions to container for see the repository
if: steps.verify-documentation-update.outputs.doc == 'true'
run: git config --global --add safe.directory /sinergym
- name: Compile documentation
if: steps.verify-documentation-update.outputs.doc == 'true'
run: docker run -v ${GITHUB_WORKSPACE}/docs/compilation:/workspaces/sinergym/docs/compilation -t pushmain/sinergym:latest /bin/bash -c 'sphinx-multiversion docs/source docs/compilation'
- name: Check sphinx spelling
if: steps.verify-documentation-update.outputs.doc == 'true'
run: docker run -t pushmain/sinergym:latest /bin/bash -c 'sphinx-build -M spelling docs/source docs/compilation'
- name: Pull local repository (needed if format commit has been done before)
if: steps.verify-documentation-update.outputs.doc == 'true'
run: git pull origin main
- name: Commit and push changes if exists
if: steps.verify-documentation-update.outputs.doc == 'true'
uses: stefanzweifel/git-auto-commit-action@v5
with:
file_pattern: docs/compilation/*
commit_message: Documentation source update detected and pushed compilation build directory for Github Pages
tests:
needs: [apply-autopep8]
name: tests execution and CodeCov upload
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build the latest Docker image
run: docker build . --file Dockerfile --build-arg SINERGYM_EXTRAS=[test] --tag pushmain/sinergym:latest
- name: Create a shared folder for coverage output
run: mkdir shared
- name: Execute tests from container
run: docker run -v ${GITHUB_WORKSPACE}/shared:/shared -t pushmain/sinergym:latest /bin/bash -c 'pytest -vv --cov sinergym --cov-report=xml tests/ && mv coverage.xml /shared'
- name: Upload to CodeCov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: /home/runner/work/sinergym/sinergym/shared/coverage.xml
fail_ci_if_error: true
verbose: true
update-dockerhub:
needs: [apply-autopep8]
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
# If you don't have secrets configured with docker credential, this job will be skipped
name: Container build and upload in Docker Hub
runs-on: ubuntu-latest
steps:
- name: Checkout code
if: "${{ env.DOCKER_USER != '' && env.DOCKER_PASSWORD != '' }}"
uses: actions/checkout@v4
- name: Build the latest Docker image
if: "${{ env.DOCKER_USER != '' && env.DOCKER_PASSWORD != '' }}"
run: docker build . --file Dockerfile --build-arg SINERGYM_EXTRAS=[extras] --tag $DOCKER_USER/sinergym:latest
- name: Build the latest lite Docker image
if: "${{ env.DOCKER_USER != '' && env.DOCKER_PASSWORD != '' }}"
run: docker build . --file Dockerfile --build-arg SINERGYM_EXTRAS=[test] --tag $DOCKER_USER/sinergym:latest-lite
- name: Login in Docker Hub account
if: "${{ env.DOCKER_USER != '' && env.DOCKER_PASSWORD != '' }}"
run: docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- name: Push container with all extras
if: "${{ env.DOCKER_USER != '' && env.DOCKER_PASSWORD != '' }}"
run: docker push $DOCKER_USER/sinergym:latest
- name: Push container used with test
if: "${{ env.DOCKER_USER != '' && env.DOCKER_PASSWORD != '' }}"
run: docker push $DOCKER_USER/sinergym:latest-lite