-
Notifications
You must be signed in to change notification settings - Fork 76
135 lines (130 loc) · 4.4 KB
/
release.yaml
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
name: Release
on:
release:
types: [published, edited]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-artifact:
name: Build noisepy-seis package
runs-on: ubuntu-20.04
if: github.repository == 'noisepy/NoisePy'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for all branches and tags.
- name: Set up Python
uses: actions/setup-python@v4.5.0
with:
python-version: 3.9
- name: Install dependencies
run: python -m pip install build
- name: Build source and wheel distributions
run: |
python -m build
echo ""
echo "Generated files:"
ls -lh dist/
- uses: actions/upload-artifact@v3
with:
name: releases
path: dist
test-built-dist:
name: Test noisepy-seis package
needs: build-artifact
runs-on: ubuntu-20.04
steps:
- uses: actions/setup-python@v4.5.0
name: Install Python
with:
python-version: 3.9
- uses: actions/download-artifact@v3
with:
name: releases
path: dist
- name: List contents of built dist
run: |
ls -ltrh
ls -ltrh dist
- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@v1.8.5
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
verbose: true
skip_existing: true
- name: Setup MPI pre-requisite
uses: mpi4py/setup-mpi@v1
- name: Check pypi packages
id: check_pkg
run: |
# Install local wheel to get the version number
pip install dist/noisepy_seis*.whl
latest_version="$(python -c 'import noisepy.seis; print(noisepy.seis.__version__)')";export latest_version
echo "latest_version=$latest_version" >> $GITHUB_OUTPUT
echo "=== Got version $latest_version from local wheel install ==="
python -m pip uninstall --yes noisepy-seis
sleep 5
python -m pip install --upgrade pip
echo "=== Testing wheel file ==="
# Install wheel to get dependencies and check import
python -m pip install --extra-index-url https://test.pypi.org/simple --upgrade --pre noisepy-seis==$latest_version
noisepy --help
echo "=== Done testing wheel file ==="
echo "=== Testing source tar file ==="
# Install tar gz and check import
python -m pip uninstall --yes noisepy-seis
python -m pip install --extra-index-url https://test.pypi.org/simple --upgrade --pre --no-binary=noisepy-seis noisepy-seis==$latest_version
python -c "import noisepy.seis; print(noisepy.seis.__version__)"
noisepy --help
echo "=== Done testing source tar file ==="
outputs:
package-version: ${{steps.check_pkg.outputs.latest_version}}
publish-pypi:
name: Push noisepy-seis to production pypi
needs: test-built-dist
if: startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: releases
path: dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@v1.8.5
with:
password: ${{ secrets.PYPI_API_TOKEN }}
push_to_registry:
name: Push Docker image to Docker Hub
needs: [publish-pypi, test-built-dist]
runs-on: ubuntu-latest
steps:
- name: Delay for PyPI
run: sleep 5 # Wait for the package to be available in PyPI
- name: Check out the repo
uses: actions/checkout@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Log in to registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}
build-args: VERSION=${{needs.test-built-dist.outputs.package-version}}