|
| 1 | +name: Build webinterface docker |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | +env: |
| 8 | + REGISTRY: ghcr.io |
| 9 | + IMAGE_NAME: ${{ github.repository }} |
| 10 | + LINGODB_REPOSITORY: lingo-db/lingodb-test-actions |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-docker: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: read |
| 17 | + packages: write |
| 18 | + attestations: write |
| 19 | + id-token: write |
| 20 | + steps: |
| 21 | + - name: Log in to the Container registry |
| 22 | + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 |
| 23 | + with: |
| 24 | + registry: ${{ env.REGISTRY }} |
| 25 | + username: ${{ github.actor }} |
| 26 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v3 |
| 29 | + - name: Set up Node.js |
| 30 | + uses: actions/setup-node@v3 |
| 31 | + with: |
| 32 | + node-version: 18 |
| 33 | + - name: Create docker-build path |
| 34 | + run: mkdir docker-uild |
| 35 | + - name: Install dependencies |
| 36 | + run: yarn install |
| 37 | + working-directory: frontend |
| 38 | + - name: Build WebInterface Frontend |
| 39 | + run: env REACT_APP_API_URL="" env BUILD_PATH="../../../docker-build/frontend" yarn workspace @lingodb/interface build |
| 40 | + working-directory: frontend |
| 41 | + - name: Authenticate GitHub CLI |
| 42 | + run: echo "${{ secrets.LINGODB_TOKEN }}" | gh auth login --with-token |
| 43 | + - name: Read LingoDB Commit |
| 44 | + id: get-lingodb-commit |
| 45 | + run: echo "lingodb_commit=$(cat lingodb-commit.txt)" >> $GITHUB_OUTPUT |
| 46 | + - name: Trigger build of lingodb binaries |
| 47 | + id: trigger-build |
| 48 | + run: | |
| 49 | + gh api repos/${{ env.LINGODB_REPOSITORY }}/actions/workflows/release-for-webinterface.yml/dispatches -F ref="main" -F inputs[ref]="b0d8f7a6f5be75a1b545ac54764473048f36b5d7" |
| 50 | +
|
| 51 | + - name: Wait for a few seconds |
| 52 | + run: sleep 5 |
| 53 | + |
| 54 | + - name: Get workflow run ID |
| 55 | + id: get-run-id |
| 56 | + run: | |
| 57 | + run_id=$(gh api repos/${{ env.LINGODB_REPOSITORY }}/actions/workflows/release-for-webinterface.yml/runs | jq -r '.workflow_runs[0].id') |
| 58 | + echo "build_run_id=$run_id" >> $GITHUB_OUTPUT |
| 59 | + - name: Get Workflow Run Status and Wait |
| 60 | + id: wait-for-run |
| 61 | + run: | |
| 62 | + build_run_id="${{ steps.get-run-id.outputs.build_run_id }}" |
| 63 | +
|
| 64 | + echo "Checking status of workflow run with ID $build_run_id" |
| 65 | +
|
| 66 | + while :; do |
| 67 | + status=$(gh api \ |
| 68 | + repos/${{ env.LINGODB_REPOSITORY }}/actions/runs/$build_run_id \ |
| 69 | + --jq '.status') |
| 70 | +
|
| 71 | + echo "Current status: $status" |
| 72 | +
|
| 73 | + if [[ "$status" == "completed" ]]; then |
| 74 | + conclusion=$(gh api \ |
| 75 | + repos/${{ env.LINGODB_REPOSITORY }}/actions/runs/$build_run_id \ |
| 76 | + --jq '.conclusion') |
| 77 | +
|
| 78 | + echo "Workflow completed with conclusion: $conclusion" |
| 79 | +
|
| 80 | + if [[ "$conclusion" != "success" ]]; then |
| 81 | + echo "Workflow did not succeed. Failing current workflow." |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | +
|
| 85 | + break |
| 86 | + fi |
| 87 | +
|
| 88 | + echo "Waiting for 10 seconds before checking again..." |
| 89 | + sleep 10 |
| 90 | + done |
| 91 | + - name: Download and Extract LingoDB binaries |
| 92 | + run: | |
| 93 | + build_run_id="${{ steps.get-run-id.outputs.build_run_id }}" |
| 94 | +
|
| 95 | + echo "Fetching artifact for workflow run ID $build_run_id" |
| 96 | +
|
| 97 | + artifact_id=$(gh api \ |
| 98 | + repos/${{ env.LINGODB_REPOSITORY }}/actions/runs/$build_run_id/artifacts \ |
| 99 | + --jq '.artifacts[0].id') |
| 100 | +
|
| 101 | + echo "Artifact ID: $artifact_id" |
| 102 | +
|
| 103 | + gh api \ |
| 104 | + repos/${{ env.LINGODB_REPOSITORY }}/actions/artifacts/$artifact_id/zip > artifact.zip |
| 105 | +
|
| 106 | + mkdir -p docker-build |
| 107 | + unzip artifact.zip -d docker-build/lingodb-binaries |
| 108 | +
|
| 109 | + echo "Artifact extracted to docker-build directory." |
| 110 | + - name: Build and push Docker image |
| 111 | + id: push |
| 112 | + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 |
| 113 | + with: |
| 114 | + context: . |
| 115 | + push: true |
| 116 | + tags: ghcr.io/lingo-db/webinterface:latest, ghcr.io/lingo-db/webinterface:${{ github.sha }} |
| 117 | + - name: Generate artifact attestation |
| 118 | + uses: actions/attest-build-provenance@v2 |
| 119 | + with: |
| 120 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} |
| 121 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 122 | + push-to-registry: true |
| 123 | + |
0 commit comments