|
1 | 1 | name: Build Docker image |
2 | 2 |
|
3 | | -on: |
4 | | - push: |
5 | | - branches: master |
| 3 | +on: [push, pull_request] |
6 | 4 |
|
7 | 5 | jobs: |
8 | 6 | main: |
9 | 7 | name: Docker |
10 | | - if: github.repository_owner == 'XboxDev' |
11 | 8 | runs-on: ubuntu-latest |
12 | 9 | timeout-minutes: 20 |
13 | 10 | strategy: |
| 11 | + fail-fast: false |
14 | 12 | matrix: |
15 | 13 | image-name: [nxdk, nxdk-debug, nxdk-lto] |
16 | 14 | include: |
17 | 15 | - image-name: nxdk |
18 | 16 | build-args: buildparams=CFLAGS=-O2 CXXFLAGS=-O2 |
| 17 | + tag: latest |
19 | 18 | - image-name: nxdk-debug |
20 | 19 | build-args: buildparams=DEBUG=y |
| 20 | + tag: lto |
21 | 21 | - image-name: nxdk-lto |
22 | 22 | build-args: buildparams=LTO=y CFLAGS=-O2 CXXFLAGS=-O2 |
| 23 | + tag: debug |
23 | 24 | steps: |
24 | 25 | - name: Clone Tree |
25 | 26 | uses: actions/checkout@v3 |
26 | 27 | with: |
27 | 28 | submodules: recursive |
28 | | - - name: Generate timestamp |
29 | | - id: timestamp |
30 | | - run: echo ::set-output name=timestamp::$(date --rfc-3339=seconds --utc) |
31 | | - - name: Generate tags |
32 | | - id: tags |
| 29 | + - name: Set variables |
33 | 30 | run: | |
34 | | - DOCKER_IMAGE=xboxdev/${{ matrix.image-name }} |
35 | | - TAGS="${DOCKER_IMAGE}:latest" |
36 | | - TAGS="$TAGS,${DOCKER_IMAGE}:git-${GITHUB_SHA::8}" |
37 | | - TAGS="$TAGS,ghcr.io/${DOCKER_IMAGE}:latest" |
38 | | - TAGS="$TAGS,ghcr.io/${DOCKER_IMAGE}:git-${GITHUB_SHA::8}" |
39 | | - echo ::set-output name=tags::${TAGS} |
| 31 | + echo "DOCKER_TAG=$(echo ghcr.io/${{ github.repository }}:${{ matrix.tag }}|tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV |
| 32 | + echo "CREATED=$(date --rfc-3339=seconds --utc)" >> $GITHUB_ENV |
| 33 | + echo "SHORT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV |
40 | 34 | - name: Set up Docker Buildx |
41 | 35 | uses: docker/setup-buildx-action@v2 |
42 | | - - name: Login to DockerHub |
43 | | - uses: docker/login-action@v2 |
| 36 | + - name: Build Docker image |
| 37 | + uses: docker/build-push-action@v3 |
44 | 38 | with: |
45 | | - username: ${{ secrets.DOCKERHUB_USERNAME }} |
46 | | - password: ${{ secrets.DOCKERHUB_TOKEN }} |
47 | | - - name: Login to GitHub Container Registry |
| 39 | + push: false |
| 40 | + tags: ${{ env.DOCKER_TAG}} |
| 41 | + build-args: ${{ matrix.build-args }} |
| 42 | + - name: Test Docker image |
| 43 | + run: | |
| 44 | + cd samples |
| 45 | + for dir in */ |
| 46 | + do |
| 47 | + cd "$dir" |
| 48 | + docker run --rm -v `pwd`:/usr/src/app -t "${DOCKER_TAG}" make -j`nproc` |
| 49 | + cd .. |
| 50 | + done |
| 51 | +
|
| 52 | + - name: Login to Docker Registry |
48 | 53 | uses: docker/login-action@v2 |
| 54 | + if: github.ref == 'refs/heads/master' |
49 | 55 | with: |
50 | 56 | registry: ghcr.io |
51 | | - username: ${{ github.actor }} |
| 57 | + username: ${{ github.repository_owner }} |
52 | 58 | password: ${{ secrets.GITHUB_TOKEN }} |
53 | | - - name: Build and push |
| 59 | + - name: Build Docker Image |
54 | 60 | uses: docker/build-push-action@v3 |
55 | 61 | with: |
56 | | - context: . |
57 | | - file: ./Dockerfile |
| 62 | + push: true |
58 | 63 | build-args: ${{ matrix.build-args }} |
59 | | - platforms: linux/amd64,linux/386 |
| 64 | + labels: | |
| 65 | + org.opencontainers.image.revision=${{ github.sha }} |
| 66 | + org.opencontainers.image.created=${{ env.CREATED }} |
| 67 | + tags: ${DOCKER_TAG} |
| 68 | + |
| 69 | + - name: Push to XboxDev Group |
| 70 | + uses: docker/build-push-action@v3 |
| 71 | + if: github.repository_owner == 'XboxDev' && github.ref == 'refs/heads/master' |
| 72 | + with: |
60 | 73 | push: true |
61 | | - tags: ${{ steps.tags.outputs.tags }} |
| 74 | + build-args: ${{ matrix.build-args }} |
| 75 | + labels: | |
| 76 | + org.opencontainers.image.revision=${{ github.sha }} |
| 77 | + org.opencontainers.image.created=${{ env.CREATED }} |
| 78 | + tags: | |
| 79 | + ghcr.io/xboxdev/${{ matrix.image-name }}:latest |
| 80 | + ghcr.io/xboxdev/${{ matrix.image-name }}:git-${{ env.SHORT_SHA }} |
| 81 | +
|
| 82 | + - name: Login to Docker Hub |
| 83 | + uses: docker/login-action@v2 |
| 84 | + if: github.repository_owner == 'XboxDev' && github.ref == 'refs/heads/master' |
| 85 | + with: |
| 86 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 87 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 88 | + - name: Push to Docker Hub |
| 89 | + uses: docker/build-push-action@v3 |
| 90 | + if: github.repository_owner == 'XboxDev' && github.ref == 'refs/heads/master' |
| 91 | + with: |
| 92 | + push: true |
| 93 | + build-args: ${{ matrix.build-args }} |
62 | 94 | labels: | |
63 | 95 | org.opencontainers.image.revision=${{ github.sha }} |
64 | | - org.opencontainers.image.created=${{ steps.timestamp.outputs.timestamp }} |
| 96 | + org.opencontainers.image.created=${{ env.CREATED }} |
| 97 | + tags: | |
| 98 | + xboxdev/${{ matrix.image-name }}:latest |
| 99 | + xboxdev/${{ matrix.image-name }}:git-${{ env.SHORT_SHA }} |
0 commit comments