Skip to content

ci: docker build cmd wip #1

ci: docker build cmd wip

ci: docker build cmd wip #1

# .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 }}