From e113562818b86e31d6e9f284cb6c19ae13df1883 Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Tue, 18 Jul 2023 12:53:15 +0200 Subject: [PATCH] wip on pr_env github workflow --- .github/workflows/pr_env.yaml | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/pr_env.yaml diff --git a/.github/workflows/pr_env.yaml b/.github/workflows/pr_env.yaml new file mode 100644 index 0000000000..8f3eefda76 --- /dev/null +++ b/.github/workflows/pr_env.yaml @@ -0,0 +1,64 @@ +name: Pull request environment + +on: + pull_request: + types: + - opened + - synchronize + +env: + MANTAINERS: "[\"cdimonaco\"]" + PR_ENV_LABEL: env + PR_NUMBER: "${{ github.event.pull_request.number }}" + +jobs: + check_env_creation_privilege: + name: Check if the environment creation criteria are met, store in the job output + runs-on: ubuntu-latest + outputs: + create_env: ${{ steps.check.outputs.create_env }} + steps: + - id: check + run: echo "create_env=${{ contains(fromJson(env.MANTAINERS), github.event.sender.login) && contains(github.event.pull_request.labels.*.name, env.PR_ENV_LABEL) }}" >> "$GITHUB_OUTPUT" + + build-and-push-pr-image: + needs: check_env_creation_privilege + name: Build and push pull request container image + runs-on: ubuntu-latest + if: needs.check_env_creation_privilege.outputs.create_env == 'true' + permissions: + contents: read + packages: write + env: + REGISTRY: ghcr.io + IMAGE_REPOSITORY: ghcr.io/${{ github.repository_owner }}/trento-web + IMAGE_TAG: ${{ github.event.pull_request.number }}-env + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: docker/setup-buildx-action@v2 + - name: Log in to the Container registry + uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 + with: + images: ${{ env.IMAGE_REPOSITORY }} + - name: Build and push container image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ env.IMAGE_REPOSITORY }}:${{ env.IMAGE_TAG }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max