|
6 | 6 | - "opendata.swiss/ui/**" # Only trigger if files in the ui directory change
|
7 | 7 | - ".github/workflows/docker-ods-ui.yaml" # Trigger also if this workflow file is changed
|
8 | 8 |
|
| 9 | + pull_request: |
| 10 | + paths: |
| 11 | + - "opendata.swiss/ui/**" # Only trigger if files in the ui directory change |
| 12 | + - ".github/workflows/docker-ods-ui.yaml" # Trigger also if this workflow file is changed |
| 13 | + |
9 | 14 | jobs:
|
10 | 15 | docker:
|
11 | 16 | runs-on: ubuntu-latest
|
|
19 | 24 | - name: Checkout
|
20 | 25 | uses: actions/checkout@v5
|
21 | 26 |
|
| 27 | + - name: Set up kubectl |
| 28 | + if: github.event_name == 'pull_request' |
| 29 | + uses: azure/setup-kubectl@v4 |
| 30 | + with: |
| 31 | + version: v1.33.0 |
| 32 | + |
| 33 | + - name: Set up Kustomize |
| 34 | + if: github.event_name == 'pull_request' |
| 35 | + uses: imranismail/setup-kustomize@v2 |
| 36 | + |
22 | 37 | - name: Install Cosign
|
| 38 | + if: github.event_name != 'pull_request' |
23 | 39 | uses: sigstore/cosign-installer@v3.9.2
|
24 | 40 |
|
25 | 41 | - name: Set up QEMU
|
|
35 | 51 | username: ${{ github.actor }}
|
36 | 52 | password: ${{ secrets.GITHUB_TOKEN }}
|
37 | 53 |
|
| 54 | + - name: Configure some variables |
| 55 | + id: vars |
| 56 | + run: | |
| 57 | + echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 58 | + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" >> $GITHUB_OUTPUT |
| 59 | +
|
38 | 60 | - name: Docker meta
|
39 | 61 | id: docker_meta
|
40 | 62 | uses: docker/metadata-action@v5
|
|
60 | 82 | linux/amd64
|
61 | 83 |
|
62 | 84 | - name: Sign the images with GitHub OIDC Token
|
| 85 | + if: github.event_name != 'pull_request' |
63 | 86 | env:
|
64 | 87 | DIGEST: ${{ steps.docker_build.outputs.digest }}
|
65 | 88 | TAGS: ${{ steps.docker_meta.outputs.tags }}
|
|
69 | 92 | images+="${tag}@${DIGEST} "
|
70 | 93 | done
|
71 | 94 | cosign sign --yes ${images}
|
| 95 | +
|
| 96 | + - name: Configure cluster context |
| 97 | + if: github.event_name == 'pull_request' |
| 98 | + run: | |
| 99 | + kubectl config set-cluster default "--server=${K8S_API_URL}" --insecure-skip-tls-verify=true |
| 100 | + kubectl config set-credentials default "--token=${K8S_TOKEN}" |
| 101 | + kubectl config set-context default --cluster=default --namespace=piveau-previews --user=default |
| 102 | + kubectl config use-context default |
| 103 | +
|
| 104 | + - name: Generate manifests |
| 105 | + if: github.event_name == 'pull_request' |
| 106 | + working-directory: ./opendata.swiss/ui/k8s |
| 107 | + run: | |
| 108 | + kustomize edit set nameprefix "${{ steps.vars.outputs.branch }}-" |
| 109 | + kustomize edit add patch --patch "$(cat <<EOF |
| 110 | + apiVersion: networking.k8s.io/v1 |
| 111 | + kind: Ingress |
| 112 | + metadata: |
| 113 | + name: piveau-ui |
| 114 | + spec: |
| 115 | + tls: |
| 116 | + - secretName: ${{ steps.vars.outputs.branch }}-prev-tls |
| 117 | + hosts: |
| 118 | + - ${{ steps.vars.outputs.branch }}.piveau-ln-preview.zazukoians.org |
| 119 | + EOF |
| 120 | + )" |
| 121 | + kustomize edit set image "ghcr.io/opendata-swiss/ods-ui=ghcr.io/opendata-swiss/ods-ui:sha-${{ steps.vars.outputs.short_sha }}" |
| 122 | + kustomize edit set label "app.kubernetes.io/instance:${{ steps.vars.outputs.branch }}" |
| 123 | + kustomize build | tee manifest.yaml |
0 commit comments