From 26b594f1a6ab8bc8d558fdc38d33d49160b13e72 Mon Sep 17 00:00:00 2001 From: Jason Boutte Date: Fri, 8 Mar 2024 22:56:38 -0800 Subject: [PATCH] Fixes creating temp pr version --- .github/workflows/containers.yaml | 98 ++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 33 deletions(-) diff --git a/.github/workflows/containers.yaml b/.github/workflows/containers.yaml index 30a8946..3b0087d 100644 --- a/.github/workflows/containers.yaml +++ b/.github/workflows/containers.yaml @@ -18,40 +18,37 @@ concurrency: cancel-in-progress: true jobs: - build-minimal-notebook: + get-issue-number: runs-on: ubuntu-latest - name: Build minimal-notebook + name: Get PR number permissions: - packages: write + contents: read + outputs: + pr-number: "${{ steps.pr-number.outputs.pr-number }}" steps: - - uses: actions/checkout@v4 - - uses: docker/setup-buildx-action@v3 - - uses: docker/login-action@v3 + - uses: actions/github-script@v6 + id: get-issue-number with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/setup-python@v5 - with: - python-version: '3.9' - - id: get-version - run: | - pip install tbump - pushd dockerfiles/minimal-notebook - echo "version=$(tbump current-version)" >> $GITHUB_OUTPUT - - uses: docker/build-push-action@v5 - with: - cache-from: type=gha - cache-to: type=gha,mode=max - context: dockerfiles/minimal-notebook - push: ${{ github.event_name == 'push' }} - tags: ghcr.io/esgf-nimbus/minimal-notebook:${{ steps.get-version.outputs.version }} + script: | + if (context.issue.number) { + return context.issue.number; + } else { + return ( + await github.rest.repos.listPullRequestAssociatedWithCommit({ + commit_sha: context.sha, + owner: context.repo.owner, + repo: context.repo.repo, + }).data[0].number; + } + result-encoding: string + - id: pr-number + run: echo "pr-number=${{ steps.get-issue-number.outputs.result }}" >> $GITHUB_OUTPUT - build-climate-notebook: + build-minimal-notebook: needs: - - build-minimal-notebook + - get-issue-number runs-on: ubuntu-latest - name: Build climate-notebook + name: Build minimal-notebook permissions: packages: write steps: @@ -67,13 +64,48 @@ jobs: python-version: '3.9' - id: get-version run: | - pip install tbump - pushd dockerfiles/climate-notebook - echo "version=$(tbump current-version)" >> $GITHUB_OUTPUT + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + echo "version=pr-${{ needs.get-issue-number.outputs.pr-number }}" >> $GITHUB_OUTPUT + else + pip install tbump + pushd dockerfiles/minimal-notebook + echo "version=$(tbump current-version)" >> $GITHUB_OUTPUT + fi - uses: docker/build-push-action@v5 with: cache-from: type=gha cache-to: type=gha,mode=max - context: dockerfiles/climate-notebook - push: ${{ github.event_name == 'push' }} - tags: ghcr.io/esgf-nimbus/climate-notebook:${{ steps.get-version.outputs.version }} + context: dockerfiles/minimal-notebook + push: true + tags: ghcr.io/esgf-nimbus/minimal-notebook:${{ steps.get-version.outputs.version }} + +# build-climate-notebook: +# needs: +# - build-minimal-notebook +# runs-on: ubuntu-latest +# name: Build climate-notebook +# permissions: +# packages: write +# steps: +# - uses: actions/checkout@v4 +# - uses: docker/setup-buildx-action@v3 +# - uses: docker/login-action@v3 +# with: +# registry: ghcr.io +# username: ${{ github.actor }} +# password: ${{ secrets.GITHUB_TOKEN }} +# - uses: actions/setup-python@v5 +# with: +# python-version: '3.9' +# - id: get-version +# run: | +# pip install tbump +# pushd dockerfiles/climate-notebook +# echo "version=$(tbump current-version)" >> $GITHUB_OUTPUT +# - uses: docker/build-push-action@v5 +# with: +# cache-from: type=gha +# cache-to: type=gha,mode=max +# context: dockerfiles/climate-notebook +# push: ${{ github.event_name == 'push' }} +# tags: ghcr.io/esgf-nimbus/climate-notebook:${{ steps.get-version.outputs.version }}