Test Issue - ignore #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Mike Deployment Trigger | |
on: | |
issue_comment: | |
types: [created] | |
jobs: | |
handle_comment: | |
runs-on: ubuntu-latest | |
if: startsWith(github.event.comment.body, '/mike deploy') || startsWith(github.event.comment.body, '/mike help') | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Fetches all history for all branches and tags | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
if: startsWith(github.event.comment.body, '/mike deploy') | |
with: | |
python-version: 3.x | |
- name: Install Requirements | |
run: pip install -r requirements.txt | |
if: startsWith(github.event.comment.body, '/mike deploy') | |
- name: Validate User | |
id: validate_user | |
run: | | |
USER_PERMISSION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/collaborators/${{ github.actor }}/permission") | |
echo "User permissions: $USER_PERMISSION" | |
if [[ "$USER_PERMISSION" =~ (\"permission\": \"admin\") ]]; then | |
echo "User is authorized to deploy." | |
echo "::set-output name=can_deploy::true" | |
else | |
echo "::error::User is not authorized to deploy." | |
echo "::set-output name=can_deploy::false" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup Git Config | |
if: env.can_deploy == 'true' | |
run: | | |
git config --global user.name "Docs Deploy" | |
git config --global user.email "kuadrant@googlegroups.com" | |
- name: Deploy Docs | |
if: env.can_deploy == 'true' | |
run: | | |
VERSION=$(echo "${{ github.event.comment.body }}" | cut -d " " -f 3) | |
BRANCH=$(echo "${{ github.event.comment.body }}" | awk -F'sourceBranch=' '{print $2}') | |
mike deploy $VERSION -t "$VERSION" --push --branch $BRANCH | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Comment Deployment Status | |
if: steps.validate_user.outputs.can_deploy == 'true' | |
run: | | |
VERSION=$(echo "${{ github.event.comment.body }}" | cut -d " " -f 3) | |
echo "Deployed $VERSION to https://docs.kuadrant.io/$VERSION" > comment.md | |
gh issue comment ${{ github.event.issue.number }} --body "$(cat comment.md)" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Provide Help | |
if: startsWith(github.event.comment.body, '/mike help') | |
run: | | |
echo "To deploy documentation using mike, use the command format:" > comment.md | |
echo "/mike deploy [version] sourceBranch=[branch]" >> comment.md | |
echo "Example: /mike deploy 0.7.0 sourceBranch=0.7.x" >> comment.md | |
gh issue comment ${{ github.event.issue.number }} --body "$(cat comment.md)" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |