|
1 | 1 | ---
|
2 |
| -name: Build a new image and then upload the image, tags and manifests to GitHub artifacts |
| 2 | +name: Build Docker image |
| 3 | + |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + tags: |
| 10 | + - v* |
| 11 | + workflow_dispatch: |
3 | 12 |
|
4 | 13 | env:
|
5 |
| - OWNER: ${{ github.repository_owner }} |
6 | 14 | FORCE_COLOR: 1
|
| 15 | + IMAGE: ghcr.io/aiidalab/qe |
| 16 | + BUILDKIT_PROGRESS: plain |
7 | 17 |
|
8 |
| -on: |
9 |
| - workflow_call: |
10 |
| - inputs: |
11 |
| - image: |
12 |
| - description: Image name |
13 |
| - required: true |
14 |
| - type: string |
15 |
| - architecture: |
16 |
| - description: Image architecture, e.g. amd64, arm64 |
17 |
| - required: true |
18 |
| - type: string |
19 |
| - runsOn: |
20 |
| - description: GitHub Actions Runner image |
21 |
| - required: true |
22 |
| - type: string |
| 18 | +# https://docs.github.com/en/actions/using-jobs/using-concurrency |
| 19 | +concurrency: |
| 20 | + # only cancel in-progress jobs or runs for the current workflow - matches against branch & tags |
| 21 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 22 | + cancel-in-progress: true |
23 | 23 |
|
24 | 24 | jobs:
|
25 | 25 | build-test-upload:
|
26 |
| - runs-on: ${{ inputs.runsOn }} |
| 26 | + runs-on: ubuntu-latest |
27 | 27 | continue-on-error: true
|
28 | 28 |
|
29 | 29 | steps:
|
30 | 30 | - name: Checkout Repo ⚡️
|
31 | 31 | uses: actions/checkout@v4
|
32 |
| - - name: Create dev environment 📦 |
33 |
| - uses: ./.github/actions/create-dev-env |
| 32 | + |
| 33 | + - name: Login to Container Registry 🔑 |
| 34 | + uses: docker/login-action@v2 |
| 35 | + if: ${{ !github.event.pull_request.head.repo.fork }} |
34 | 36 | with:
|
35 |
| - architecture: ${{ inputs.architecture }} |
| 37 | + registry: ghcr.io |
| 38 | + username: ${{ github.actor }} |
| 39 | + password: ${{ secrets.GITHUB_TOKEN }} |
36 | 40 |
|
37 |
| - # Self-hosted runners share a state (whole VM) between runs |
38 |
| - # Also, they might have running or stopped containers, |
39 |
| - # which are not cleaned up by `docker system prun` |
40 |
| - - name: Reset docker state and cleanup artifacts 🗑️ |
41 |
| - if: ${{ startsWith(inputs.runsOn, 'ubuntu') }} |
42 |
| - run: | |
43 |
| - docker kill $(docker ps --quiet) || true |
44 |
| - docker rm $(docker ps --all --quiet) || true |
45 |
| - docker system prune --all --force |
46 |
| - rm -rf /tmp/aiidalab/ |
47 |
| - shell: bash |
| 41 | + - name: Set up Docker Buildx |
| 42 | + uses: docker/setup-buildx-action@v3 |
48 | 43 |
|
49 |
| - - name: Build image 🛠 |
50 |
| - working-directory: docker |
51 |
| - run: docker buildx bake --set qe.platform=linux/${{ inputs.architecture }} -f docker-bake.hcl -f build.json --load |
52 |
| - env: |
53 |
| - # Use buildx |
54 |
| - DOCKER_BUILDKIT: 1 |
55 |
| - # Full logs for CI build |
56 |
| - BUILDKIT_PROGRESS: plain |
57 |
| - shell: bash |
| 44 | + - name: Docker meta 📝 |
| 45 | + id: meta |
| 46 | + uses: docker/metadata-action@v5 |
| 47 | + with: |
| 48 | + images: | |
| 49 | + name=${{ env.IMAGE }} |
| 50 | + tags: | |
| 51 | + type=ref,event=pr |
| 52 | + type=edge,enable={{is_default_branch}} |
| 53 | + type=raw,value={{tag}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} |
58 | 54 |
|
59 |
| - - name: Run tests ✅ |
60 |
| - uses: ./.github/actions/integration-tests |
| 55 | + - name: Build and push image |
| 56 | + id: build-upload |
| 57 | + uses: docker/build-push-action@v5 |
61 | 58 | with:
|
62 |
| - architecture: ${{ inputs.architecture }} |
63 |
| - runsOn: ${{ inputs.runsOn }} |
| 59 | + tags: ${{ steps.meta.outputs.tags }} |
| 60 | + load: ${{ github.event.pull_request.head.repo.fork }} |
| 61 | + push: ${{ ! github.event.pull_request.head.repo.fork }} |
| 62 | + context: . |
| 63 | + platforms: linux/amd64 |
| 64 | + cache-to: | |
| 65 | + type=gha,scope=${{ github.workflow }},mode=min |
| 66 | + cache-from: | |
| 67 | + type=gha,scope=${{ github.workflow }} |
64 | 68 |
|
65 |
| - - name: Save image as a tar for later use 💾 |
66 |
| - run: | |
67 |
| - mkdir -p /tmp/aiidalab/ |
68 |
| - docker save ${{ env.OWNER }}/${{ inputs.image }} -o /tmp/aiidalab/${{ inputs.image }}-${{ inputs.architecture }}.tar |
69 |
| - shell: bash |
70 |
| - if: always() |
| 69 | + - name: Set Up Python 🐍 |
| 70 | + uses: actions/setup-python@v5 |
| 71 | + with: |
| 72 | + python-version: 3.11 |
| 73 | + |
| 74 | + - name: Install Dev Dependencies 📦 |
| 75 | + run: pip install -r requirements-docker.txt |
71 | 76 |
|
72 |
| - - name: Upload image as artifact 💾 |
| 77 | + - name: Set jupyter token env |
| 78 | + run: echo "JUPYTER_TOKEN=$(openssl rand -hex 32)" >> $GITHUB_ENV |
| 79 | + |
| 80 | + - name: Run pytest for Chrome |
| 81 | + run: pytest --driver Chrome tests_integration/ |
| 82 | + env: |
| 83 | + QE_IMAGE: ${{ env.IMAGE }}@${{ steps.build-upload.outputs.digest }} |
| 84 | + |
| 85 | + - name: Upload screenshots as artifacts |
| 86 | + if: always() |
73 | 87 | uses: actions/upload-artifact@v4
|
74 | 88 | with:
|
75 |
| - name: ${{ inputs.image }}-${{ inputs.architecture }} |
76 |
| - path: /tmp/aiidalab/${{ inputs.image }}-${{ inputs.architecture }}.tar |
77 |
| - retention-days: 3 |
78 |
| - if: always() |
| 89 | + name: Screenshots |
| 90 | + path: screenshots/ |
| 91 | + if-no-files-found: error |
0 commit comments