|
| 1 | +name: Energy Tracker CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'energy-tracker-*' |
| 7 | + paths: |
| 8 | + - '**' |
| 9 | + - '.github/workflows/container.yml' |
| 10 | + pull_request: |
| 11 | + paths: |
| 12 | + - '**' |
| 13 | + - '.github/workflows/container.yml' |
| 14 | + |
| 15 | +defaults: |
| 16 | + run: |
| 17 | + working-directory: . |
| 18 | + |
| 19 | +jobs: |
| 20 | + test: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Set up Python |
| 27 | + uses: actions/setup-python@v5 |
| 28 | + with: |
| 29 | + python-version: '3.13' |
| 30 | + |
| 31 | + - name: Compile check |
| 32 | + run: | |
| 33 | + python -m compileall octopus_agile_tracker |
| 34 | +
|
| 35 | + - name: Unit tests |
| 36 | + run: python -m unittest discover -s tests -v |
| 37 | + |
| 38 | + publish: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + needs: test |
| 41 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/energy-tracker-') |
| 42 | + permissions: |
| 43 | + contents: read |
| 44 | + packages: write |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Set up QEMU |
| 51 | + uses: docker/setup-qemu-action@v3 |
| 52 | + |
| 53 | + - name: Set up Docker Buildx |
| 54 | + uses: docker/setup-buildx-action@v3 |
| 55 | + |
| 56 | + - name: Log in to GHCR |
| 57 | + uses: docker/login-action@v3 |
| 58 | + with: |
| 59 | + registry: ghcr.io |
| 60 | + username: ${{ github.actor }} |
| 61 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + |
| 63 | + - name: Compute image tag |
| 64 | + id: image_tag |
| 65 | + run: | |
| 66 | + ref="${GITHUB_REF_NAME}" |
| 67 | + ver="${ref#energy-tracker-}" |
| 68 | + ver="${ver#v}" |
| 69 | + owner="${GITHUB_REPOSITORY_OWNER,,}" |
| 70 | + echo "version=${ver}" >> "$GITHUB_OUTPUT" |
| 71 | + echo "owner=${owner}" >> "$GITHUB_OUTPUT" |
| 72 | +
|
| 73 | + - name: Build and push |
| 74 | + uses: docker/build-push-action@v5 |
| 75 | + with: |
| 76 | + context: . |
| 77 | + file: ./Dockerfile |
| 78 | + build-args: | |
| 79 | + ENERGY_TRACKER_VERSION=${{ steps.image_tag.outputs.version }} |
| 80 | + push: true |
| 81 | + platforms: linux/amd64,linux/arm64 |
| 82 | + tags: | |
| 83 | + ghcr.io/${{ steps.image_tag.outputs.owner }}/energy-tracker:${{ steps.image_tag.outputs.version }} |
| 84 | + ghcr.io/${{ steps.image_tag.outputs.owner }}/energy-tracker:latest |
| 85 | + cache-from: type=gha,scope=energy-tracker |
| 86 | + cache-to: type=gha,mode=max,scope=energy-tracker |
0 commit comments