From d78843df08bce366c290acc4fda972121ed7c50d Mon Sep 17 00:00:00 2001 From: greg pereira Date: Tue, 12 Nov 2024 07:19:03 -0800 Subject: [PATCH] implement clearer tagging system Signed-off-by: greg pereira --- .../workflows/{images.yml => pr-images.yml} | 0 .github/workflows/release-images.yml | 66 +++++++++++++++++++ 2 files changed, 66 insertions(+) rename .github/workflows/{images.yml => pr-images.yml} (100%) create mode 100644 .github/workflows/release-images.yml diff --git a/.github/workflows/images.yml b/.github/workflows/pr-images.yml similarity index 100% rename from .github/workflows/images.yml rename to .github/workflows/pr-images.yml diff --git a/.github/workflows/release-images.yml b/.github/workflows/release-images.yml new file mode 100644 index 00000000..8bc74ffa --- /dev/null +++ b/.github/workflows/release-images.yml @@ -0,0 +1,66 @@ +# name: Deploy To Prodcution +# on: +# release: +# types: [released] + +name: test-wf +on: + pull_request: + branches: + - main +env: + GHCR_REGISTRY: ghcr.io + GHCR_UI_IMAGE_NAME: ${{ github.repository }}/ui + QUAY_REGISTRY: quay.io + QUAY_UI_IMAGE_NAME: instructlab-ui/ui + GHCR_PATHSERVICE_IMAGE_NAME: ${{ github.repository }}/pathservice + QUAY_PATHSERVICE_IMAGE_NAME: instructlab-ui/pathservice + +jobs: + check_most_recent_pr_number: + runs-on: ubuntu-latest + steps: + - name: Get Pull Request Number from Commit + id: get_pr_number + uses: actions/github-script@v6 + with: + script: | + console.log("Repository owner:", context.repo.owner); + console.log("Repository name:", context.repo.repo); + console.log("Current commit SHA:", context.sha); + + const commits = await github.rest.repos.listCommits({ + owner: context.repo.owner, + repo: context.repo.repo, + sha: context.sha, + per_page: 1 + }); + const commitSha = commits.data[0].sha; + console.log("Fetched commit SHA:", commitSha); + + const prs = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'closed', + sort: 'updated', + direction: 'desc' + }); + console.log("Number of closed PRs fetched:", prs.data.length); + + const pr = prs.data.find(pr => pr.merge_commit_sha === commitSha); + if (pr) { + console.log("Matching PR found:", pr.number); + return pr.number; + } else { + console.log("No matching PR found for commit SHA:", commitSha); + return ''; + } + result-encoding: string + + - name: Build and Tag Docker Image + if: steps.get_pr_number.outputs.result != '' + env: + PR_NUMBER: ${{ steps.get_pr_number.outputs.result }} + run: | + echo my-image:pr-${PR_NUMBER} +