Run tests before publish and release. #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test, Publish, Release | |
| on: | |
| push: | |
| branches: [main] | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: # Manual trigger | |
| pull_request: | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| env: | |
| REGISTRY: docker.io | |
| IMAGE_NAME: itomek/gaia-dev | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python 3.12 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| - name: Install test dependencies | |
| run: uv sync --extra dev | |
| - name: Run Dockerfile build tests | |
| run: | | |
| uv run pytest tests/test_dockerfile.py -v --tb=short | |
| - name: Run entrypoint tests | |
| run: | | |
| uv run pytest tests/test_entrypoint.py -v --tb=short | |
| - name: Run integration tests | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| run: | | |
| uv run pytest tests/test_container.py -v --tb=short -m integration | |
| build-and-push: | |
| needs: test | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Read VERSION file | |
| id: version | |
| run: | | |
| VERSION=$(cat VERSION | tr -d '[:space:]') | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "GAIA version: $VERSION" | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=${{ steps.version.outputs.version }} | |
| type=sha | |
| - name: Build and push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| GAIA_VERSION=${{ steps.version.outputs.version }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| update-description: | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Update Docker Hub description | |
| uses: peter-evans/dockerhub-description@v4 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| repository: ${{ env.IMAGE_NAME }} | |
| short-description: "GAIA Linux container" | |
| readme-filepath: ./README.md | |
| create-release: | |
| runs-on: ubuntu-latest | |
| needs: [build-and-push, update-description] | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Create GitHub release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| VERSION="v${{ needs.build-and-push.outputs.version }}" | |
| if gh release view "$VERSION" >/dev/null 2>&1; then | |
| echo "Release $VERSION exists, deleting to overwrite." | |
| gh release delete "$VERSION" --yes | |
| fi | |
| gh release create "$VERSION" \ | |
| --title "$VERSION" \ | |
| --notes "Docker image published: ${{ env.IMAGE_NAME }}:${{ needs.build-and-push.outputs.version }}" \ | |
| --target "${{ github.sha }}" |