-
Notifications
You must be signed in to change notification settings - Fork 1
187 lines (163 loc) · 6.75 KB
/
build.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: Build
on:
push:
branches: [ develop, release/**, main, feature/**, issue/**, dependabot/** ]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
PYTHON_VERSION: '3.11'
POETRY_VERSION: '1.8.1'
jobs:
build:
name: Build, Test, Verify, Publish
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
outputs:
version: ${{ steps.versioning.outputs.new_version }}
changes: ${{ steps.check_changes.outputs.changes }}
pyproject_name: ${{ steps.versioning.outputs.pyproject_name }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for proper versioning
- name: Setup Python and Poetry
uses: ./github/workflows/setup-python-poetry
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
- name: Version Management
id: versioning
run: |
# Combine version management logic into a single step
pyproject_name=$(poetry version | awk '{print $1}')
echo "pyproject_name=${pyproject_name}" >> $GITHUB_OUTPUT
current_version=$(poetry version -s)
echo "old_version=${current_version}" >> $GITHUB_ENV
# Version calculation based on branch
if [[ "${{ github.ref }}" =~ ^refs/heads/(issue|feature|dependabot)/ ]]; then
new_version="${current_version%%-*}+$(git rev-parse --short HEAD)"
elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
if [[ ${current_version} =~ -alpha ]]; then
alpha_num=$((${current_version##*alpha.} + 1))
new_version="${current_version%%-*}-alpha.${alpha_num}"
else
new_version="${current_version}-alpha.1"
fi
elif [[ "${{ github.ref }}" =~ ^refs/heads/release/ ]]; then
if [[ ${current_version} =~ -rc ]]; then
rc_num=$((${current_version##*rc.} + 1))
new_version="${current_version%%-*}-rc.${rc_num}"
else
new_version="${current_version}-rc.1"
fi
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
new_version=${current_version%%-*}
fi
echo "new_version=${new_version}" >> $GITHUB_OUTPUT
echo "the_version=${new_version}" >> $GITHUB_ENV
poetry version ${new_version}
- name: Install Dependencies and Run Tests
run: |
poetry install
poetry run pylint podaac
poetry run flake8 podaac
poetry run pytest --junitxml=build/reports/pytest.xml --cov=podaac/ --cov-report=html -m "not aws and not integration" tests/
- name: Security Scan
uses: snyk/actions/python@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: test
args: --org=${{ secrets.SNYK_ORG_ID }} --project-name=${{ github.repository }} --severity-threshold=high --fail-on=all
- name: Build Package
run: poetry build
- name: Check for Changes
id: check_changes
if: |
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release')
run: |
git diff --quiet || echo "changes=true" >> $GITHUB_OUTPUT
- name: Git Operations
if: steps.check_changes.outputs.changes == 'true'
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git commit -am "/version ${{ env.the_version }}"
git tag -a "${{ env.the_version }}" -m "Version ${{ env.the_version }}"
git push --follow-tags
- name: Create and Upload Release
if: |
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release')
uses: ncipollo/[email protected]
with:
tag: ${{ env.the_version }}
artifacts: "*.zip"
token: ${{ secrets.GITHUB_TOKEN }}
makeLatest: ${{ github.ref == 'refs/heads/main' }}
prerelease: ${{ github.ref != 'refs/heads/main' }}
publish:
needs: build
if: |
success() && (
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release') ||
contains(github.event.head_commit.message, '/deploy')
)
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
- name: Setup Python and Poetry
uses: ./github/workflows/setup-python-poetry
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
- name: Build Package
run: poetry build
- name: Get Local Forge-py Build
if: contains(github.event.head_commit.message, '/deploy')
run: |
local_forge_py=$(find dist -type f -name "*.whl")
echo "local_forge_py=${local_forge_py}" >> $GITHUB_ENV
- name: Publish to PyPI
if: "!contains(github.event.head_commit.message, '/deploy')"
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
POETRY_PYPI_TOKEN_TESTPYPI: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
poetry publish
else
poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry publish -r testpypi
fi
- name: Wait for package
if: |
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release/')
run: |
pip install tenacity logging
python3 ${GITHUB_WORKSPACE}/.github/workflows/wait-for-pypi.py ${{needs.build.outputs.pyproject_name}}[harmony]==${{ needs.build.outputs.version }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/lambdaDockerfileArm
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build.outputs.version }}
platforms: linux/arm64
build-args: |
DIST_PATH: ${{ contains(github.event.head_commit.message, '/deploy') && 'dist/' || '' }}
SOURCE: ${{ env.local_forge_py != '' && env.local_forge_py || format('{0}=={1}', needs.build.outputs.pyproject_name, needs.build.outputs.version) }}
cache-from: type=registry,ref=podaac/forge-py:cache
cache-to: type=registry,ref=podaac/forge-py:cache,mode=max