-
Notifications
You must be signed in to change notification settings - Fork 1
109 lines (92 loc) · 3.59 KB
/
pull_request.yml
File metadata and controls
109 lines (92 loc) · 3.59 KB
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
name: Pull Request
on:
pull_request:
branches:
- "main"
jobs:
run-linters:
name: Run linters
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install Python dependencies
run: pip install black
- name: Run linters
uses: wearerequired/lint-action@v2
with:
black: true
run-tests:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pip install pytest
pip install pytest-cov
pip install mock
pip install pytest-httpserver
python -m pytest --cov-config=.coveragerc --cov=. --cov-branch --exitfirst --verbose --failed-first --cov-fail-under=70
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
needs: [run-tests, run-linters]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Generate Tag
id: generate_tag
run: |
sha=${{ github.event.pull_request.head.sha }}
tag="SNAPSHOT-PR-${{ github.event.pull_request.number }}-${sha:0:8}"
echo "##[set-output name=GIT_TAG;]$(echo ${tag})"
- name: Login to Docker Hub
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Generate image repository path
id: image_repository_op
run: |
echo IMAGE_REPOSITORY=$(echo ${{ secrets.REGISTRY_LOGIN_SERVER }}/${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
- name: Build and push image
run: |
docker build . -t ${{ env.IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_TAG }} \
--build-arg SERVICEBUS_CONNECTION_STR="${{ secrets.SERVICEBUS_CONNECTION_STR }}" \
--build-arg SERVICEBUS_TOPIC_NAME="${{ secrets.SERVICEBUS_TOPIC_NAME }}" \
--build-arg SERVICEBUS_SUBSCRIPTION_NAME="${{ secrets.SERVICEBUS_SUBSCRIPTION_NAME }}" \
--label org.opencontainers.image.source=${{ github.event.repository.clone_url }} \
--label org.opencontainers.image.revision=${{ github.sha }}
docker push ${{ env.IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_TAG }}
- name: Comment on PR
uses: mshick/add-pr-comment@v1
env:
GITHUB_TOKEN: ${{ secrets.ECM3440_GITHUB_TOKEN }}
with:
message: "@${{ github.actor }} Image is available for testing. `docker pull ${{ env.IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_TAG }}`"
allow-repeats: false
- name: Notify Failure
if: failure()
uses: mshick/add-pr-comment@v1
env:
GITHUB_TOKEN: ${{ secrets.ECM3440_GITHUB_TOKEN }}
with:
message: "@${{ github.actor }} Yikes! You better fix it before anyone else finds out! [Build](https://github.com/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }}/checks) has Failed!"
allow-repeats: false