Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Running Hackathon by Yourself with GitHub Actions, Microsoft 365 and Power Platform
name: On Team Page Requested
on:
workflow_dispatch:
inputs:
teamName:
description: The name of team
required: true
default: Team_HackaLearn
content:
description: The content of the file to be created
required: true
default: Hello HackaLearn
- name: Create team page
uses: DamianReeves/write-file-action@master
with:
path: "./teams/${{ github.event.inputs.teamName }}.md"
contents: ${{ github.event.inputs.content }}
write-mode: overwrite
- name: Commit team page
shell: bash
run: |
git config --local user.email "hackalearn.korea@outlook.com"
git config --local user.name "HackaLearn Korea"
git add ./teams/\* --force
git commit -m "Team: ${{ github.event.inputs.teamName }} added"
- name: Push team page
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
name: On Challenge Submitted
on:
pull_request_target:
types:
- opened
branches:
- main
paths:
- 'teams/**/*.md'
jobs:
labelling:
name: 'Add a label on submission: review-required'
runs-on: ubuntu-latest
steps:
- name: Get PR date/time
id: checkpoint
shell: pwsh
run: |
$tz = [TimeZoneInfo]::FindSystemTimeZoneById("Asia/Seoul")
$dateSubmitted = [DateTimeOffset]::Parse("${{ github.event.pull_request.created_at }}")
$offset = $tz.GetUtcOffset($dateSubmitted)
$dateSubmitted = $dateSubmitted.ToOffset($offset)
$dateDue = $([DateTimeOffset]::Parse("2021-08-16T00:00:00.000+09:00"))
$isOverdue = "$($dateSubmitted -gt $dateDue)".ToLowerInvariant()
$dateSubmittedValue = $dateSubmitted.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz")
$dateDueValue = $dateDue.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz")
echo "::set-output name=dateSubmitted::$dateSubmittedValue"
echo "::set-output name=dateDue::$dateDueValue"
echo "::set-output name=isOverdue::$isOverdue"
- name: Add a label - Overdue
if: ${{ steps.checkpoint.outputs.isOverdue == 'true' }}
uses: buildsville/add-remove-label@v1
with:
token: "${{ secrets.GITHUB_TOKEN }}"
label: 'OVERDUE-SUBMIT'
type: add
- name: Comment to PR - Overdue
if: ${{ steps.checkpoint.outputs.isOverdue == 'true' }}
uses: bubkoo/auto-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pullRequestOpened: |
๐Ÿ‘‹๐Ÿผ @{{ author }} ๋‹˜!
* PR ์ œ์ถœ ์‹œ๊ฐ: ${{ steps.checkpoint.outputs.dateSubmitted }}
* PR ๋งˆ๊ฐ ์‹œ๊ฐ: ${{ steps.checkpoint.outputs.dateDue }}
์•ˆํƒ€๊น๊ฒŒ๋„ ์ œ์ถœํ•˜์‹  PR์€ ๋งˆ๊ฐ ๊ธฐํ•œ์ธ ${{ steps.checkpoint.outputs.dateDue }}์„ ๋„˜๊ธฐ์…จ์Šต๋‹ˆ๋‹ค. ๐Ÿ˜ญ ๋”ฐ๋ผ์„œ, ์ด๋ฒˆ HackaLearn ์ด๋ฒคํŠธ์— ๋ฐ˜์˜๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
๊ทธ๋™์•ˆ HackaLearn ์ด๋ฒคํŠธ์— ์ฐธ์—ฌํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌ ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ๋‹ค์Œ ๊ธฐํšŒ์— ๋‹ค์‹œ ๋งŒ๋‚˜์š”!
- name: Close PR - Overdue
if: ${{ steps.checkpoint.outputs.isOverdue == 'true' }}
uses: superbrothers/close-pull-request@v3
with:
comment: "์ œ์ถœ ๊ธฐํ•œ ์ข…๋ฃŒ"
- name: Add a label
if: ${{ steps.checkpoint.outputs.isOverdue == 'false' }}
uses: actions/labeler@v3
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: '.github/labeler.yml'
- name: Comment to PR
if: ${{ steps.checkpoint.outputs.isOverdue == 'false' }}
uses: bubkoo/auto-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pullRequestOpenedReactions: 'rocket, +1'
pullRequestOpened: >
๐Ÿ‘‹๐Ÿผ @{{ author }} ๋‹˜!
<br>
์ฑŒ๋ฆฐ์ง€ ์™„๋ฃŒ PR๋ฅผ ์ƒ์„ฑํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๐ŸŽ‰ ์ฐธ๊ฐ€์ž๋‹˜์˜ ํ•ด์ปคํ†ค ์™„์ฃผ๋ฅผ ์‘์›ํ•ด์š”! ๐Ÿ’ช๐Ÿผ
<br>
PR ํ…œํ”Œ๋ฆฟ ์ž‘์„ฑ ๊ฐ€์ด๋“œ๋ผ์ธ์„ ์ž˜ ์ค€์ˆ˜ํ•˜์…จ๋Š”์ง€ ํ™•์ธํ•ด์ฃผ์„ธ์š”. ์ตœ๋Œ€ํ•œ ๋น ๋ฅด๊ฒŒ ๋ฆฌ๋ทฐํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค! ๐Ÿ˜Š
<br><br>
๐Ÿ”น From. HackaLearn ์šด์˜์ง„ ์ผ๋™ ๐Ÿ”น
- name: Randomly assign a staff
if: ${{ steps.checkpoint.outputs.isOverdue == 'false' }}
uses: gerardabello/auto-assign@v1.0.1
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
number-of-assignees: 1
assignee-pool: "${{ secrets.PR_REVIEWERS }}"
name: On Challenge Labelled
on:
pull_request_target:
types:
- labeled
- unlabeled
jobs:
labelling:
name: 'Update a label'
runs-on: ubuntu-latest
steps:
- name: Respond to label
uses: dessant/label-actions@v2
with:
process-only: prs
name: On Challenge Review Commented
on:
issue_comment:
types:
- created
env:
PR_REVIEWERS: ${{ secrets.PR_REVIEWERS }}
jobs:
signoff:
if: ${{ github.event.issue.pull_request }}
name: 'Sign-off challenge'
runs-on: ubuntu-latest
steps:
- name: Get checkpoints
id: checkpoint
shell: pwsh
run: |
$hasValidLabel = "${{ contains(github.event.issue.labels.*.name, 'review-completed') }}"
$isCommenterAssignee = "${{ github.event.comment.user.login == github.event.issue.assignee.login }}"
$isValidCommenter = "${{ contains(env.PR_REVIEWERS, github.event.comment.user.login) }}"
$isAswaSignoff = "${{ github.event.comment.body == '/aswasignoff' }}"
$isGhaSignoff = "${{ github.event.comment.body == '/ghasignoff' }}"
$isSocialSignoff = "${{ github.event.comment.body == '/socialsignoff' }}"
$isAppSignoff = "${{ github.event.comment.body == '/appsignoff' }}"
$isRepoSignoff = "${{ github.event.comment.body == '/reposignoff' }}"
$isRetroSignoff = "${{ github.event.comment.body == '/retrosignoff' }}"
$timestamp = "${{ github.event.comment.created_at }}"
echo "::set-output name=hasValidLabel::$hasValidLabel"
echo "::set-output name=isCommenterAssignee::$isCommenterAssignee"
echo "::set-output name=isValidCommenter::$isValidCommenter"
echo "::set-output name=isAswaSignoff::$isAswaSignoff"
echo "::set-output name=isGhaSignoff::$isGhaSignoff"
echo "::set-output name=isSocialSignoff::$isSocialSignoff"
echo "::set-output name=isAppSignoff::$isAppSignoff"
echo "::set-output name=isRepoSignoff::$isRepoSignoff"
echo "::set-output name=isRetroSignoff::$isRetroSignoff"
echo "::set-output name=timestamp::$timestamp"
- name: Record challenge ASWA
if: ${{ steps.checkpoint.outputs.hasValidLabel == 'true' && steps.checkpoint.outputs.isCommenterAssignee == 'true' && steps.checkpoint.outputs.isValidCommenter == 'true' && steps.checkpoint.outputs.isAswaSignoff == 'true' }}
uses: joelwmale/webhook-action@2.1.0
with:
url: ${{ secrets.FLOW_URL }}
body: '{"gitHubId": "${{ github.event.issue.user.login }}", "challengeType": "aswa", "timestamp": "${{ steps.checkpoint.outputs.timestamp }}", "prId": ${{ github.event.issue.number }} }'
- name: Record challenge GHA
if: ${{ steps.checkpoint.outputs.hasValidLabel == 'true' && steps.checkpoint.outputs.isCommenterAssignee == 'true' && steps.checkpoint.outputs.isValidCommenter == 'true' && steps.checkpoint.outputs.isGhaSignoff == 'true' }}
uses: joelwmale/webhook-action@2.1.0
with:
url: ${{ secrets.FLOW_URL }}
body: '{"gitHubId": "${{ github.event.issue.user.login }}", "challengeType": "gha", "timestamp": "${{ steps.checkpoint.outputs.timestamp }}", "prId": ${{ github.event.issue.number }} }'
- name: Record challenge SOCIAL
if: ${{ steps.checkpoint.outputs.hasValidLabel == 'true' && steps.checkpoint.outputs.isCommenterAssignee == 'true' && steps.checkpoint.outputs.isValidCommenter == 'true' && steps.checkpoint.outputs.isSocialSignoff == 'true' }}
uses: joelwmale/webhook-action@2.1.0
with:
url: ${{ secrets.FLOW_URL }}
body: '{"gitHubId": "${{ github.event.issue.user.login }}", "challengeType": "social", "timestamp": "${{ steps.checkpoint.outputs.timestamp }}", "prId": ${{ github.event.issue.number }} }'
- name: Record challenge APP
if: ${{ steps.checkpoint.outputs.hasValidLabel == 'true' && steps.checkpoint.outputs.isCommenterAssignee == 'true' && steps.checkpoint.outputs.isValidCommenter == 'true' && steps.checkpoint.outputs.isAppSignoff == 'true' }}
uses: joelwmale/webhook-action@2.1.0
with:
url: ${{ secrets.FLOW_URL }}
body: '{"gitHubId": "${{ github.event.issue.user.login }}", "challengeType": "app", "timestamp": "${{ steps.checkpoint.outputs.timestamp }}", "prId": ${{ github.event.issue.number }} }'
- name: Record challenge REPO
if: ${{ steps.checkpoint.outputs.hasValidLabel == 'true' && steps.checkpoint.outputs.isCommenterAssignee == 'true' && steps.checkpoint.outputs.isValidCommenter == 'true' && steps.checkpoint.outputs.isRepoSignoff == 'true' }}
uses: joelwmale/webhook-action@2.1.0
with:
url: ${{ secrets.FLOW_URL }}
body: '{"gitHubId": "${{ github.event.issue.user.login }}", "challengeType": "repo", "timestamp": "${{ steps.checkpoint.outputs.timestamp }}", "prId": ${{ github.event.issue.number }} }'
- name: Record challenge RETRO
if: ${{ steps.checkpoint.outputs.hasValidLabel == 'true' && steps.checkpoint.outputs.isCommenterAssignee == 'true' && steps.checkpoint.outputs.isValidCommenter == 'true' && steps.checkpoint.outputs.isRetroSignoff == 'true' }}
uses: joelwmale/webhook-action@2.1.0
with:
url: ${{ secrets.FLOW_URL }}
body: '{"gitHubId": "${{ github.event.issue.user.login }}", "challengeType": "retro", "timestamp": "${{ steps.checkpoint.outputs.timestamp }}", "prId": ${{ github.event.issue.number }} }'
name: On Challenge Completed
on:
workflow_dispatch:
inputs:
prId:
description: PR ID
required: true
default: ''
labelsToAdd:
description: The comma delimited labels to add
required: true
default: record-updated
labelsToRemove:
description: The comma delimited labels to remove
required: true
default: review-completed
isMergeable:
description: The value indicating whether the challenge is mergeable or not.
required: true
default: 'false'
jobs:
update_labels:
name: 'Update labels'
runs-on: ubuntu-latest
steps:
- name: Update labels on PR
shell: pwsh
run: |
$headers = @{ "Authorization" = "token ${{ secrets.GITHUB_TOKEN }}"; "User-Agent" = "HackaLearn Bot"; "Accept" = "application/vnd.github.v3+json" }
$owner = "devrel-kr"
$repository = "HackaLearn"
$issueId = "${{ github.event.inputs.prId }}"
$labelsToAdd = "${{ github.event.inputs.labelsToAdd }}" -split ","
$body = @{ "labels" = $labelsToAdd }
$url = "https://api.github.com/repos/$owner/$repository/issues/$issueId/labels"
Invoke-RestMethod -Method Post -Uri $url -Headers $headers -Body $($body | ConvertTo-Json)
$labelsToRemove = "${{ github.event.inputs.labelsToRemove }}" -split ","
$labelsToRemove | ForEach-Object {
$label = $_;
$url = "https://api.github.com/repos/$owner/$repository/issues/$issueId/labels/$label";
Invoke-RestMethod -Method Delete -Uri $url -Headers $headers
}
merge_pr:
name: 'Merge PR'
needs: update_labels
runs-on: ubuntu-latest
steps:
- name: Merge PR
if: ${{ github.event.inputs.isMergeable == 'true' }}
shell: pwsh
run: |
$headers = @{ "Authorization" = "token ${{ secrets.WORKFLOW_DISPATCH_TOKEN }}"; "User-Agent" = "HackaLearn Bot"; "Accept" = "application/vnd.github.v3+json" }
$owner = "devrel-kr"
$repository = "HackaLearn"
$issueId = "${{ github.event.inputs.prId }}"
$url = "https://api.github.com/repos/$owner/$repository/pulls/$issueId"
$pr = Invoke-RestMethod -Method Get -Uri $url -Headers $headers
$sha = $pr.head.sha
$title = ""
$message = ""
$merge = "squash"
$body = @{ "commit_title" = $title; "commit_message" = $message; "sha" = $sha; "merge_method" = $merge; }
$url = "https://api.github.com/repos/$owner/$repository/pulls/$issueId/merge"
Invoke-RestMethod -Method Put -Uri $url -Headers $headers -Body $($body | ConvertTo-Json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment