|
1 | | -# Copyright 2025 Terradue |
2 | | -# |
3 | | -# Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | -# you may not use this file except in compliance with the License. |
5 | | -# You may obtain a copy of the License at |
6 | | -# |
7 | | -# http://www.apache.org/licenses/LICENSE-2.0 |
8 | | -# |
9 | | -# Unless required by applicable law or agreed to in writing, software |
10 | | -# distributed under the License is distributed on an "AS IS" BASIS, |
11 | | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | -# See the License for the specific language governing permissions and |
13 | | -# limitations under the License. |
14 | | - |
15 | | -name: publish-to-pypi |
16 | | - |
17 | | -# on: |
18 | | -# release: |
19 | | -# types: [created] |
| 1 | +name: build-and-publish |
| 2 | + |
20 | 3 | on: |
21 | 4 | push: |
22 | 5 | branches: |
23 | | - - develop |
24 | | - - main |
| 6 | + - develop |
| 7 | + - main |
| 8 | + tags: |
| 9 | + - 'v*.*.*' |
25 | 10 |
|
26 | 11 | permissions: |
27 | | - id-token: write # IMPORTANT: this permission is mandatory for trusted publishing |
| 12 | + id-token: write # required for trusted PyPI publishing |
28 | 13 | contents: read |
29 | 14 | packages: write |
30 | | - attestations: write |
| 15 | + |
| 16 | +env: |
| 17 | + IMAGE_ID: ghcr.io/eoepca/eoap-cwlwrap/eoap-cwlwrap |
31 | 18 |
|
32 | 19 | jobs: |
33 | | - deploy: |
| 20 | + |
| 21 | + build: |
34 | 22 |
|
35 | 23 | runs-on: ubuntu-latest |
36 | 24 |
|
37 | | - environment: release |
38 | | - |
39 | 25 | steps: |
40 | | - - uses: actions/checkout@v4 |
41 | | - - name: Set up Python |
42 | | - uses: actions/setup-python@v4 |
43 | | - with: |
44 | | - python-version: '3.10' |
45 | | - cache: 'pip' |
46 | | - - name: Install dependencies |
47 | | - run: | |
48 | | - # python -m pip install --upgrade pip |
49 | | - pip install hatch nose2 |
50 | | - - name: Build package |
51 | | - run: hatch build |
52 | | - - name: Test package |
53 | | - run: hatch test --verbose |
54 | | - - name: Publish package distributions to PyPI |
55 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
56 | | - with: |
57 | | - skip-existing: true |
58 | | - repository-url: https://upload.pypi.org/legacy/ |
59 | | - |
60 | | - container-build: |
61 | | - needs: deploy |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Set up Python |
| 29 | + uses: actions/setup-python@v4 |
| 30 | + with: |
| 31 | + python-version: "3.10" |
| 32 | + cache: "pip" |
| 33 | + |
| 34 | + - name: Install dependencies |
| 35 | + run: pip install hatch nose2 |
| 36 | + |
| 37 | + - name: Build package |
| 38 | + run: hatch build |
| 39 | + |
| 40 | + - name: Test package |
| 41 | + run: hatch test --verbose |
| 42 | + |
| 43 | + - name: Determine image tag |
| 44 | + id: vars |
| 45 | + run: | |
| 46 | + if [[ "${GITHUB_REF}" == refs/heads/develop ]]; then |
| 47 | + echo "IMAGE_TAG=latest-dev" >> $GITHUB_ENV |
| 48 | + elif [[ "${GITHUB_REF}" == refs/heads/main ]]; then |
| 49 | + echo "IMAGE_TAG=latest" >> $GITHUB_ENV |
| 50 | + elif [[ "${GITHUB_REF}" == refs/tags/v* ]]; then |
| 51 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 52 | + echo "IMAGE_TAG=$VERSION" >> $GITHUB_ENV |
| 53 | + fi |
| 54 | +
|
| 55 | + - name: Login to GHCR |
| 56 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
| 57 | + |
| 58 | + - name: Build container |
| 59 | + run: | |
| 60 | + docker build . -f Dockerfile -t eoap-cwlwrap |
| 61 | + docker tag eoap-cwlwrap $IMAGE_ID:${IMAGE_TAG} |
| 62 | +
|
| 63 | + - name: Push container |
| 64 | + run: docker push $IMAGE_ID:${IMAGE_TAG} |
| 65 | + |
| 66 | + publish-to-pypi: |
| 67 | + |
| 68 | + # Only run for version tags |
| 69 | + if: startsWith(github.ref, 'refs/tags/v') |
| 70 | + |
62 | 71 | runs-on: ubuntu-latest |
| 72 | + needs: build |
| 73 | + environment: release |
| 74 | + |
63 | 75 | steps: |
64 | | - - uses: actions/checkout@v4 |
65 | | - - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
66 | | - - name: build & push image |
67 | | - run: | |
68 | | - version=$(grep -Eo '[0-9]+(\.[0-9]+){1,3}' src/eoap_cwlwrap/__about__.py | tail -1) |
69 | | - IMAGE_ID=ghcr.io/eoepca/eoap-cwlwrap/eoap-cwlwrap |
70 | | - docker build . --file Dockerfile --tag eoap-cwlwrap |
71 | | - docker tag eoap-cwlwrap $IMAGE_ID:$version |
72 | | - docker tag eoap-cwlwrap $IMAGE_ID:latest |
73 | | - docker push $IMAGE_ID:latest |
74 | | - docker push $IMAGE_ID:$version |
| 76 | + - uses: actions/checkout@v4 |
| 77 | + |
| 78 | + - name: Set up Python |
| 79 | + uses: actions/setup-python@v4 |
| 80 | + with: |
| 81 | + python-version: "3.10" |
| 82 | + |
| 83 | + - name: Install hatch |
| 84 | + run: pip install hatch |
| 85 | + |
| 86 | + - name: Build package |
| 87 | + run: hatch build |
| 88 | + |
| 89 | + - name: Publish to PyPI (trusted publishing) |
| 90 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments