Skip to content

create_exercises

create_exercises #43

name: create_exercises
on:
workflow_dispatch:
inputs:
language:
description: 'Language'
required: true
default: text
type: choice
options:
- text
- python
- Fortran
permissions: write-all
jobs:
create-labels:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- run: gh label create ${{ inputs.language }} -f
create-pulls-matrix:
needs: create-labels
strategy:
matrix:
exercise: [1, 2, 3]
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- run: |
echo "Language: ${{ inputs.language }}"
echo "Exercise: ${{ matrix.exercise }}"
# checkout repo
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: create issue for exercise ${{ inputs.exercise }}
# check if the issue file exists before creating the issue
# store created issue in BAR to use in pull request text
env:
issueFile: 'issues/${{ inputs.language }}-ex${{ matrix.exercise }}-issue.md'
if: hashFiles(env.issueFile) !=''
run: |
echo "REPO_URL=$(gh repo view --json url --jq '.url')" >> $GITHUB_ENV
echo ${{ env.REPO_URL }}
cat issues/${{ inputs.language }}-ex${{ matrix.exercise }}-issue.md > issuebody
sed -i 's|REPO_URL|${{ env.REPO_URL }}/blob/main|g' issuebody
echo "BAR=$(gh issue create --title "${{ inputs.language }}: Exercise ${{ matrix.exercise }}" --body-file issuebody --label ${{ inputs.language }})" >> $GITHUB_ENV
- name: query_branch_exists
run: |
echo "FOO=$(git branch -r | grep "${{ inputs.language }}-${{ matrix.exercise }}")" >> $GITHUB_ENV
- name: create pull request for exercise ${{ matrix.exercise }}
run: |
if [ '${{ env.FOO }}' == '' ]; then
echo "no branch ${{ inputs.language }}-${{ matrix.exercise }} to create pull request from"
else
cat pull_requests/${{ inputs.language }}-ex${{ matrix.exercise }}-pullbody.md > pullbody
echo "Fixes ${{ env.BAR }} ${{ inputs.language }}" >> pullbody
gh pr create -B main -H "${{ inputs.language }}-${{ matrix.exercise }}" --title 'Exercise ${{ matrix.exercise }} ${{ inputs.language }}.' --body-file pullbody --label ${{ inputs.language }}
fi