-
Notifications
You must be signed in to change notification settings - Fork 10
168 lines (148 loc) · 5.03 KB
/
tests.yml
File metadata and controls
168 lines (148 loc) · 5.03 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
name: Build and Run Apigee Migration Assessment Image
on: # yamllint disable-line rule:truthy
push:
branches:
- main
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
branches:
- main
types:
- opened
- synchronize
- reopened
workflow_dispatch:
permissions: read-all
env:
REGISTRY: ghcr.io
IMAGE_NAME: ghcr.io/${{ github.repository }}/apigee-migration-assessment-tool
jobs:
unittest:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r test-requirements.txt
- name: Run unittests
run: python -m unittest discover tests -v
build-and-push:
runs-on: ubuntu-latest
needs: unittest
permissions:
contents: read
packages: write
outputs:
image_tag: ${{ steps.get_tag.outputs.tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=sha
- name: Determine primary image tag
id: get_tag
run: |
if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
echo "tag=pr-${{ github.event.number }}" >> "$GITHUB_OUTPUT"
elif [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
echo "tag=latest" >> "$GITHUB_OUTPUT"
else
# For feature branches, etc.
echo "tag=${GITHUB_REF_NAME}" | sed 's/\//-/g' >> "$GITHUB_OUTPUT"
fi
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
test-opdk:
runs-on: ubuntu-latest
needs:
- build-and-push
permissions:
id-token: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: pip install requests pyotp
- name: Generate Apigee Token
id: get_token
env:
APIGEE_EDGE_USER: ${{ secrets.APIGEE_EDGE_USER }}
APIGEE_EDGE_PASSWORD: ${{ secrets.APIGEE_EDGE_PASSWORD }}
OTP_SECRET: ${{ secrets.APIGEE_EDGE_OTP_SECRET }}
run: python tests/ci/generate_apigee_edge_access_token.py
- name: Fetch input.properties
run: |
echo "${{ secrets.APIGEE_EDGE_INPUT_PROPERTIES }}" | base64 -d > "${{ github.workspace }}/input.properties"
- name: Run tests on Apigee Edge SAAS.
run: |
mkdir ${{ github.workspace }}/output
sudo chmod 777 ${{ github.workspace }}/output
docker run \
-v "${{ github.workspace }}/input.properties:/app/input.properties" \
-v "${{ github.workspace }}/output:/app/target" \
-e "SOURCE_AUTH_TOKEN=${STEPS_GET_TOKEN_OUTPUTS_ACCESS_TOKEN}" \
"${IMAGE_NAME}:${NEEDS_BUILD_AND_PUSH_OUTPUTS_IMAGE_TAG}" \
--skip-target-validation \
--resources all
env:
STEPS_GET_TOKEN_OUTPUTS_ACCESS_TOKEN: ${{ steps.get_token.outputs.access_token }}
NEEDS_BUILD_AND_PUSH_OUTPUTS_IMAGE_TAG: ${{ needs.build-and-push.outputs.image_tag }}
- name: Upload latest assement results
uses: actions/upload-artifact@v4
with:
name: assessment-report
path: "${{ github.workspace }}/output/qualification_report.xlsx"