From 8c42397cf26b54f1dd5c54441e544cf5a47adeea Mon Sep 17 00:00:00 2001 From: Javier Evans Date: Mon, 26 Feb 2024 12:18:24 -0800 Subject: [PATCH] chore: fix bug in dev container push script --- .github/workflows/dev-preview.yml | 200 +++++++++++++++--------------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/.github/workflows/dev-preview.yml b/.github/workflows/dev-preview.yml index d2a6cdc8..a7d58069 100644 --- a/.github/workflows/dev-preview.yml +++ b/.github/workflows/dev-preview.yml @@ -1,107 +1,107 @@ name: Build and Push Dev Preview Image - on: - issue_comment: - types: - - created +on: + issue_comment: + types: + - created - jobs: - long-job: - name: Builds and pushes the docker image for the open source NGINX version to github packages - if: ${{ github.event.issue.pull_request && github.event.comment.body == '/build_dev' }} - steps: - - name: Put a reaction to the comment - run: gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NODE_ID: ${{ github.event.comment.node_id }} - - - name: Check if PR is open - run: | - STATE=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json state --jq .state) - if [ "$STATE" != "OPEN" ]; then - echo "Cannot build for closed PRs" - ( - echo "**${{ github.workflow }}**" - echo "Cannot build Kuby for a closed PR. Use the `latest` version (built for the `master` branch) or create a new PR." - ) | \ - gh pr comment "${PR_NUMBER}" --repo ${{ github.repository }} -F - - gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:THUMBS_DOWN}){reaction{content}subject{id}}}" - gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" - exit 1 - fi - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.issue.number }} - NODE_ID: ${{ github.event.comment.node_id }} - - - name: Get PR HEAD Ref - id: getRef - run: echo "pr_ref=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefOid | jq -r '.headRefOid')" >> $GITHUB_OUTPUT - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.issue.number }} - - - name: Debug print out ref info - run: echo $(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json) - - - name: Checkout source code from Github - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ steps.getRef.outputs.pr_ref }} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - # This second invocation of build/push should just use the existing build cache - - name: Build and push image [oss] - uses: docker/build-push-action@v5 - with: - file: Dockerfile.oss - context: . - push: true - platforms: linux/amd64,linux/arm64 - provenance: false - tags: | - ghcr.io/${{ github.repository }}/nginx-oss-s3-gateway:dev-${{ steps.getRef.outputs.pr_ref }} - - - name: Final Comment - run: | - gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:THUMBS_UP}){reaction{content}subject{id}}}" - gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" +jobs: + long-job: + name: Builds and pushes the docker image for the open source NGINX version to github packages + if: ${{ github.event.issue.pull_request && github.event.comment.body == '/build_dev' }} + steps: + - name: Put a reaction to the comment + run: gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_ID: ${{ github.event.comment.node_id }} + + - name: Check if PR is open + run: | + STATE=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json state --jq .state) + if [ "$STATE" != "OPEN" ]; then + echo "Cannot build for closed PRs" ( echo "**${{ github.workflow }}**" - echo "The long task is done!" - echo - echo "You can find the workflow here:" - echo "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + echo "Cannot build Kuby for a closed PR. Use the `latest` version (built for the `master` branch) or create a new PR." ) | \ - gh pr comment "${PR_NUMBER}" --repo ${{ github.repository }} -F - - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.issue.number }} - NODE_ID: ${{ github.event.comment.node_id }} - - notify-job: - needs: [build] - if: ${{ always() && contains(needs.*.result, 'failure') }} <-- check that status of the previous job - steps: - - name: Notify on Failure - run: | + gh pr comment "${PR_NUMBER}" --repo ${{ github.repository }} -F - gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:THUMBS_DOWN}){reaction{content}subject{id}}}" gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" - ( - echo "**${{ github.workflow }}**" - echo "**Something went wrong!**" - echo - echo "**Details:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" - ) | \ - gh pr comment "${PR_NUMBER}" --repo ${{ github.repository }} -F - - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.issue.number }} - NODE_ID: ${{ github.event.comment.node_id }} + exit 1 + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.issue.number }} + NODE_ID: ${{ github.event.comment.node_id }} + + - name: Get PR HEAD Ref + id: getRef + run: echo "pr_ref=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefOid | jq -r '.headRefOid')" >> $GITHUB_OUTPUT + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.issue.number }} + + - name: Debug print out ref info + run: echo $(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json) + + - name: Checkout source code from Github + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ steps.getRef.outputs.pr_ref }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + # This second invocation of build/push should just use the existing build cache + - name: Build and push image [oss] + uses: docker/build-push-action@v5 + with: + file: Dockerfile.oss + context: . + push: true + platforms: linux/amd64,linux/arm64 + provenance: false + tags: | + ghcr.io/${{ github.repository }}/nginx-oss-s3-gateway:dev-${{ steps.getRef.outputs.pr_ref }} + + - name: Final Comment + run: | + gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:THUMBS_UP}){reaction{content}subject{id}}}" + gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" + ( + echo "**${{ github.workflow }}**" + echo "The long task is done!" + echo + echo "You can find the workflow here:" + echo "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + ) | \ + gh pr comment "${PR_NUMBER}" --repo ${{ github.repository }} -F - + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.issue.number }} + NODE_ID: ${{ github.event.comment.node_id }} + + notify-job: + needs: [build] + if: ${{ always() && contains(needs.*.result, 'failure') }} <-- check that status of the previous job + steps: + - name: Notify on Failure + run: | + gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:THUMBS_DOWN}){reaction{content}subject{id}}}" + gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" + ( + echo "**${{ github.workflow }}**" + echo "**Something went wrong!**" + echo + echo "**Details:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + ) | \ + gh pr comment "${PR_NUMBER}" --repo ${{ github.repository }} -F - + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.issue.number }} + NODE_ID: ${{ github.event.comment.node_id }}