From 03403ad9cb90c13c4cb548a022e34baf71e627a4 Mon Sep 17 00:00:00 2001 From: Eric Allam Date: Fri, 24 Nov 2023 11:19:06 +0000 Subject: [PATCH] Fix for pull request workflow (#751) * Allow PRs that have /publish-docker in the body to cause docker images to be published * Also ignore mdx file changes * pr_checks now uses pull_request instead of pull_request_target --- .github/workflows/pr_checks.yml | 3 +- .github/workflows/publish-docker.yml | 72 ++++++++++++++++++++++++++++ .github/workflows/publish.yml | 72 ++-------------------------- 3 files changed, 77 insertions(+), 70 deletions(-) create mode 100644 .github/workflows/publish-docker.yml diff --git a/.github/workflows/pr_checks.yml b/.github/workflows/pr_checks.yml index 6a1cd2acc..bb917195e 100644 --- a/.github/workflows/pr_checks.yml +++ b/.github/workflows/pr_checks.yml @@ -1,11 +1,12 @@ name: 🤖 PR Checks on: - pull_request_target: + pull_request: branches: - main paths-ignore: - "**.md" + - "**.mdx" - ".github/CODEOWNERS" - ".github/ISSUE_TEMPLATE/**" diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml new file mode 100644 index 000000000..6a14ab896 --- /dev/null +++ b/.github/workflows/publish-docker.yml @@ -0,0 +1,72 @@ +name: "🐳 Publish Docker" +on: + workflow_call: +jobs: + publish: + runs-on: buildjet-4vcpu-ubuntu-2204 + outputs: + version: ${{ steps.get_version.outputs.version }} + short_sha: ${{ steps.get_commit.outputs.sha_short }} + steps: + - name: 🐳 Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: ⬇️ Checkout repo + uses: actions/checkout@v3 + + - name: 🆚 Get the version + id: get_version + run: | + IMAGE_TAG="${GITHUB_REF#refs/tags/}" + if [[ $GITHUB_REF == refs/tags/* ]]; then + if [[ $IMAGE_TAG == v.docker.* ]]; then + ORIGINAL_VERSION="${IMAGE_TAG#v.docker.}" + IMAGE_TAG="v${ORIGINAL_VERSION}" + elif [[ $IMAGE_TAG == build-* ]]; then + IMAGE_TAG="${IMAGE_TAG#build-}" + fi + echo "IMAGE_TAG=${IMAGE_TAG}" + elif [[ $GITHUB_REF == refs/heads/main ]]; then + # Handle main branch specifically + IMAGE_TAG="main" + echo "IMAGE_TAG=${IMAGE_TAG}" + else + echo "Invalid reference: ${GITHUB_REF}" + exit 1 + fi + echo "::set-output name=version::${IMAGE_TAG}" + - name: 🔢 Get the commit hash + id: get_commit + run: | + echo ::set-output name=sha_short::$(echo ${{ github.sha }} | cut -c1-7) + + - name: 🐳 Build Docker Image + run: | + docker build -t release_build_image -f ./docker/Dockerfile . + + - name: 🐙 Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: 🐙 Push to GitHub Container Registry + run: | + docker tag release_build_image $REGISTRY/$REPOSITORY:$IMAGE_TAG + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + env: + REGISTRY: ghcr.io/triggerdotdev + REPOSITORY: trigger.dev + IMAGE_TAG: ${{ steps.get_version.outputs.version }} + + - name: 🐙 Push 'latest' to GitHub Container Registry + if: startsWith(github.ref, 'refs/tags/') + run: | + docker tag release_build_image $REGISTRY/$REPOSITORY:latest + docker push $REGISTRY/$REPOSITORY:latest + env: + REGISTRY: ghcr.io/triggerdotdev + REPOSITORY: trigger.dev diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3a4f2fb47..109936fe3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,9 +4,9 @@ on: push: branches: - main - - improvements/* tags: - "v.docker.*" + - "build-*" paths: - ".github/workflows/publish.yml" - "packages/**" @@ -51,71 +51,5 @@ jobs: publish: needs: [typecheck, units, e2e] - runs-on: buildjet-4vcpu-ubuntu-2204 - outputs: - version: ${{ steps.get_version.outputs.version }} - short_sha: ${{ steps.get_commit.outputs.sha_short }} - steps: - - name: 🐳 Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: ⬇️ Checkout repo - uses: actions/checkout@v3 - - - name: 🆚 Get the version - id: get_version - run: | - IMAGE_TAG="${GITHUB_REF#refs/tags/}" - if [[ $GITHUB_REF == refs/tags/* ]]; then - if [[ $IMAGE_TAG == v.docker.* ]]; then - ORIGINAL_VERSION="${IMAGE_TAG#v.docker.}" - IMAGE_TAG="v${ORIGINAL_VERSION}" - fi - echo "IMAGE_TAG=${IMAGE_TAG}" - elif [[ $GITHUB_REF == refs/heads/improvements/* ]]; then - ORIGINAL_VERSION="${GITHUB_REF#refs/heads/improvements/}" - IMAGE_TAG="${ORIGINAL_VERSION}.rc" - echo "IMAGE_TAG=${IMAGE_TAG}" - elif [[ $GITHUB_REF == refs/heads/* ]]; then - IMAGE_TAG="${GITHUB_REF#refs/heads/}" - echo "IMAGE_TAG=${IMAGE_TAG}" - else - echo "Invalid reference: ${GITHUB_REF}" - exit 1 - fi - echo "::set-output name=version::${IMAGE_TAG}" - - name: 🔢 Get the commit hash - id: get_commit - run: | - echo ::set-output name=sha_short::$(echo ${{ github.sha }} | cut -c1-7) - - - name: 🐳 Build Docker Image - run: | - docker build -t release_build_image -f ./docker/Dockerfile . - - - name: 🐙 Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: 🐙 Push to GitHub Container Registry - run: | - docker tag release_build_image $REGISTRY/$REPOSITORY:$IMAGE_TAG - docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - env: - REGISTRY: ghcr.io/triggerdotdev - REPOSITORY: trigger.dev - IMAGE_TAG: ${{ steps.get_version.outputs.version }} - - - name: 🐙 Push 'latest' to GitHub Container Registry - if: startsWith(github.ref, 'refs/tags/') - run: | - docker tag release_build_image $REGISTRY/$REPOSITORY:latest - docker push $REGISTRY/$REPOSITORY:latest - env: - REGISTRY: ghcr.io/triggerdotdev - REPOSITORY: trigger.dev + uses: ./.github/workflows/publish-docker.yml + secrets: inherit