|
| 1 | +name: docker-unstable-slim |
| 2 | + |
| 3 | +# This workflow uses actions that are not certified by GitHub. |
| 4 | +# They are provided by a third-party and are governed by |
| 5 | +# separate terms of service, privacy policy, and support |
| 6 | +# documentation. |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: [unstable-slim] |
| 11 | + tags: ["*"] |
| 12 | + pull_request: |
| 13 | + branches: [unstable-slim] |
| 14 | + |
| 15 | +env: |
| 16 | + # Use docker.io for Docker Hub if empty |
| 17 | + REGISTRY: docker.io |
| 18 | + # github.repository as <account>/<repo> |
| 19 | + IMAGE_NAME: wukan0621/sysu-lang |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + packages: write |
| 27 | + # This is used to complete the identity challenge |
| 28 | + # with sigstore/fulcio when running outside of PRs. |
| 29 | + id-token: write |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout repository |
| 33 | + uses: actions/checkout@v3 |
| 34 | + with: |
| 35 | + submodules: false |
| 36 | + |
| 37 | + # Extract metadata (tags, labels) for Docker |
| 38 | + # https://github.com/docker/metadata-action |
| 39 | + - name: Extract Docker metadata |
| 40 | + id: meta |
| 41 | + uses: docker/metadata-action@v4 |
| 42 | + with: |
| 43 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 44 | + |
| 45 | + # Workaround: https://github.com/docker/build-push-action/issues/461 |
| 46 | + - name: Setup Docker buildx |
| 47 | + uses: docker/setup-buildx-action@v2 |
| 48 | + |
| 49 | + # Build Docker image with Buildx |
| 50 | + # https://github.com/docker/build-push-action |
| 51 | + - name: Build Docker image |
| 52 | + id: build |
| 53 | + uses: docker/build-push-action@v3 |
| 54 | + with: |
| 55 | + context: . |
| 56 | + load: true |
| 57 | + tags: ${{ steps.meta.outputs.tags }} |
| 58 | + labels: ${{ steps.meta.outputs.labels }} |
| 59 | + |
| 60 | + - name: Run Tests |
| 61 | + uses: addnab/docker-run-action@v3 |
| 62 | + continue-on-error: true |
| 63 | + with: |
| 64 | + image: ${{ steps.meta.outputs.tags }} |
| 65 | + run: | |
| 66 | + export CTEST_OUTPUT_ON_FAILURE=1 |
| 67 | + cmake --build ~/sysu/build -t test |
| 68 | +
|
| 69 | + # Login against a Docker registry except on PR |
| 70 | + # https://github.com/docker/login-action |
| 71 | + - name: Log into registry ${{ env.REGISTRY }} |
| 72 | + if: github.event_name != 'pull_request' |
| 73 | + uses: docker/login-action@v2 |
| 74 | + with: |
| 75 | + registry: ${{ env.REGISTRY }} |
| 76 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 77 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 78 | + |
| 79 | + - name: Setup Docker qemu |
| 80 | + uses: docker/setup-qemu-action@v2 |
| 81 | + |
| 82 | + # Build and push Docker image with Buildx (don't push on PR) |
| 83 | + # https://github.com/docker/build-push-action |
| 84 | + - name: Build and push Docker image |
| 85 | + id: build-and-push |
| 86 | + uses: docker/build-push-action@v3 |
| 87 | + with: |
| 88 | + platforms: linux/amd64,linux/arm64,linux/riscv64 |
| 89 | + context: . |
| 90 | + push: ${{ github.event_name != 'pull_request' }} |
| 91 | + tags: ${{ steps.meta.outputs.tags }} |
| 92 | + labels: ${{ steps.meta.outputs.labels }} |
| 93 | + |
| 94 | + # Install the cosign tool except on PR |
| 95 | + # https://github.com/sigstore/cosign-installer |
| 96 | + - name: Install cosign |
| 97 | + if: github.event_name != 'pull_request' |
| 98 | + |
| 99 | + |
| 100 | + # Sign the resulting Docker image digest except on PRs. |
| 101 | + # This will only write to the public Rekor transparency log when the Docker |
| 102 | + # repository is public to avoid leaking data. If you would like to publish |
| 103 | + # transparency data even for private images, pass --force to cosign below. |
| 104 | + # https://github.com/sigstore/cosign |
| 105 | + - name: Sign the published Docker image |
| 106 | + if: ${{ github.event_name != 'pull_request' }} |
| 107 | + env: |
| 108 | + COSIGN_EXPERIMENTAL: "true" |
| 109 | + # This step uses the identity token to provision an ephemeral certificate |
| 110 | + # against the sigstore community Fulcio instance. |
| 111 | + run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }} |
0 commit comments