Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands in PRs to build release candidates #693

Closed
Tracked by #692
mempirate opened this issue Jan 17, 2025 · 0 comments · Fixed by #695
Closed
Tracked by #692

Commands in PRs to build release candidates #693

mempirate opened this issue Jan 17, 2025 · 0 comments · Fixed by #695
Labels
A: infra Area: Infrastructure

Comments

@mempirate
Copy link
Contributor

mempirate commented Jan 17, 2025

Context

We can use the issue_comment trigger with a predefined command (such as /build bolt-sidecar:v0.5.0-alpha.rc1) to build images in CI on our self-hosted runners on-demand.

Considerations

  • Only allow core contributors to run this command
  • Would be nice to get a comment from github actions when the build is completed

Template from ChatGPT:

(Needs security checks)

# .github/workflows/docker-build-on-comment.yml
name: Build Docker Image on Comment

on:
  issue_comment:
    types: [created]

jobs:
  build:
    if: |
      github.event.issue.pull_request != null &&
      startsWith(github.event.comment.body, '/build ')
    runs-on: ubuntu-latest

    steps:
      - name: Extract subdirectory and tag from comment
        id: extract
        run: |
          echo "Comment: ${{ github.event.comment.body }}"
          if [[ "${{ github.event.comment.body }}" =~ ^/build[[:space:]]+([^:]+):(.+)$ ]]; then
            echo "subdir=${BASH_REMATCH[1]}" >> $GITHUB_ENV
            echo "tag=${BASH_REMATCH[2]}" >> $GITHUB_ENV
          else
            echo "Comment does not match the expected pattern."
            exit 1
          fi

      - name: Checkout PR code
        uses: actions/checkout@v3
        with:
          ref: ${{ github.event.issue.pull_request.head.ref }}

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Log in to GitHub Container Registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push Docker image
        uses: docker/build-push-action@v4
        with:
          context: ./${{ env.subdir }}
          push: true
          tags: ghcr.io/${{ github.repository_owner }}/${{ env.subdir }}:${{ env.tag }}

      - name: Post comment on PR
        uses: thollander/actions-comment-pull-request@v1
        with:
          message: |
            The Docker image has been successfully built and pushed to GHCR.
            Image: `ghcr.io/${{ github.repository_owner }}/${{ env.subdir }}:${{ env.tag }}`
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: infra Area: Infrastructure
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant