Skip to content

Commit

Permalink
wip on pr_env github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
CDimonaco committed Jul 18, 2023
1 parent ad6b679 commit e113562
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/pr_env.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e113562

Please sign in to comment.