Skip to content

Commit

Permalink
Local commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Akrog committed Apr 23, 2020
1 parent 4513e6b commit 05fa282
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 2 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/build-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: build-command
on:
repository_dispatch:
types: [build-command]
jobs:
build:
env:
AUTHORIZED: ${{ github.actor != github.event.client_payload.pull_request.base.repo.owner.login }}
# github.actor == github.event.repository.owner.login
RESULT_REACTION: "+1"
RESULT_MESSAGE: ${{ null }}
SOURCE_BRANCH: master
DOCKER_REPO: embercsi/ci_images
IMAGE_TAG: ${{ format('{0}-{1}', github.event.client_payload.pull_request.number, github.event.client_payload.pull_request.head.sha) }}

# runs-on: ubuntu-latest
runs-on: self-hosted

steps:
# Checkout the pull request branch from the other repository
- uses: actions/checkout@v2
if: env.AUTHORIZED == 'true'
with:
token: ${{ secrets.TOKEN }}
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.ref }}

- name: Notify of start of command
if: env.AUTHORIZED == 'true'
uses: peter-evans/create-or-update-comment@v1
with:
token: ${{ secrets.TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: rocket
body: |
> [Build run output][1]
[1]: ${{ format('https://github.com/{0}/actions/runs/{1}', github.repository, github.run_id) }}
# TODO: Check if image exists in docker and skip building if exists unless we receive the force parameter

- name: Build image
if: env.AUTHORIZED == 'true'
run: |
echo 'Start'
echo "::add-mask::${{ secrets.DOCKER_PASSWORD }}"
EMBER_VERSION=$IMAGE_TAG hooks/build
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
docker tag $DOCKER_REPO:master7 $DOCKER_REPO:${IMAGE_TAG}-7
docker tag $DOCKER_REPO:master8 $DOCKER_REPO:${IMAGE_TAG}-8
docker push $DOCKER_REPO:${IMAGE_TAG}-7
docker push $DOCKER_REPO:${IMAGE_TAG}-8
echo 'Done'
- name: Set failed result
if: failure()
run: echo "::set-env name=RESULT_REACTION::-1"

- name: Set not authorized result
if: env.AUTHORIZED == 'false'
run: |
echo "::set-env name=RESULT_REACTION::confused"
echo "::set-env name=RESULT_MESSAGE::User not authorized to run command"
- name: Notify result on the comment
if: always()
uses: peter-evans/create-or-update-comment@v1
with:
token: ${{ secrets.TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: ${{ env.RESULT_REACTION }}
body: ${{ env.RESULT_MESSAGE }}

17 changes: 15 additions & 2 deletions .github/workflows/command-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@ jobs:
uses: peter-evans/slash-command-dispatch@v1
with:
token: ${{ secrets.TOKEN }}
commands: help, build
repository: embercsi/3rd-party-ci
# commands: help, build
issue-type: pull-request
reactions: false
# repository: embercsi/3rd-party-ci
# permission: write
config: >
[
{
"command": "help",
"permission": "read",
"issue_type": "pull-request"
},
{
"command": "build",
"permission": "write",
"issue_type": "pull-request"
}
]
32 changes: 32 additions & 0 deletions .github/workflows/help-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: help-command
on:
repository_dispatch:
types: [help-command]
jobs:
help:
runs-on: ubuntu-latest
env:
AUTHORIZED: ${{ github.actor != github.event.client_payload.pull_request.base.repo.owner.login }}
# github.actor == github.event.repository.owner.login
RESULT_MESSAGE: |
> Your available commands are:
> Command | Description
> --- | ---
> /help | Reply comment with help for available slash commands
ADMIN_COMMANDS: |
> /build | Build container image (maintainers only)
steps:
# run: echo ::set-output name=result_message::Sorry, slash commands are only available for maintainers.
# The true is necessary: https://github.community/t5/GitHub-Actions/Implementing-Dry-Run-Logic-If-and-env/td-p/49882
- if: env.AUTHORIZED == 'true'
run: echo "::set-env name=RESULT_MESSAGE::${RESULT_MESSAGE//$'\n'/'%0A'}${ADMIN_COMMANDS//$'\n'/'%0A'}"
# run: echo "::set-output name=result_message::${ADMIN_COMMANDS//$'\n'/'%0A'}"

- name: Update comment
uses: peter-evans/create-or-update-comment@v1
with:
token: ${{ secrets.TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: ${{ env.RESULT_MESSAGE }}
# body: ${{ steps.vars.outputs.result_message }}

0 comments on commit 05fa282

Please sign in to comment.