|
| 1 | +name: Initial Repository Setup |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + paths: |
| 9 | + - '.github/workflows/setup.yml' |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + issues: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + minimal-setup: |
| 17 | + if: github.repository != 'EnderModuBot/template' |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Replace placeholders in issue template |
| 25 | + env: |
| 26 | + OWNER: ${{ github.repository_owner }} |
| 27 | + REPO: ${{ github.event.repository.name }} |
| 28 | + run: | |
| 29 | + sed -i "s|{{owner}}|$OWNER|g" .github/setup-reminder.md |
| 30 | + sed -i "s|{{repo}}|$REPO|g" .github/setup-reminder.md |
| 31 | +
|
| 32 | + - name: Create setup reminder issue |
| 33 | + uses: JasonEtco/create-an-issue@v2 |
| 34 | + env: |
| 35 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + with: |
| 37 | + filename: .github/setup-reminder.md |
| 38 | + |
| 39 | + - name: Create / update default issue labels |
| 40 | + shell: bash |
| 41 | + run: | |
| 42 | + declare -A labels=( |
| 43 | + ["breaking"]="d20f48:Breaking changes or backwards-incompatible updates" |
| 44 | + ["feature"]="2ecc71:New functionality or enhancements" |
| 45 | + ["maintenance"]="f39c12:Codebase cleanup or non-feature updates" |
| 46 | + ["performance"]="f1c40f:Performance-related improvements" |
| 47 | + ["tests"]="1abc9c:Adding or updating tests" |
| 48 | + ) |
| 49 | +
|
| 50 | + for name in "${!labels[@]}"; do |
| 51 | + IFS=':' read -r color desc <<< "${labels[$name]}" |
| 52 | +
|
| 53 | + # Erstellt das Label, fällt bei 422 (already exists) zurück auf PATCH |
| 54 | + status=$(curl -s -o /dev/null -w "%{http_code}" -X POST \ |
| 55 | + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 56 | + -H "Accept: application/vnd.github+json" \ |
| 57 | + -d "{\"name\":\"${name}\",\"color\":\"${color}\",\"description\":\"${desc}\"}" \ |
| 58 | + "https://api.github.com/repos/${{ github.repository }}/labels") |
| 59 | +
|
| 60 | + if [ "$status" = "422" ]; then |
| 61 | + curl -s -X PATCH \ |
| 62 | + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 63 | + -H "Accept: application/vnd.github+json" \ |
| 64 | + -d "{\"new_name\":\"${name}\",\"color\":\"${color}\",\"description\":\"${desc}\"}" \ |
| 65 | + "https://api.github.com/repos/${{ github.repository }}/labels/${name}" |
| 66 | + fi |
| 67 | + done |
| 68 | +
|
| 69 | + - name: Delete this workflow file |
| 70 | + run: | |
| 71 | + git config --global user.name "setup-bot" |
| 72 | + git config --global user.email "setup@github.com" |
| 73 | + git rm -f .github/workflows/setup.yml |
| 74 | + git rm -f .github/setup-reminder.md |
| 75 | + git commit -m "chore: remove setup workflow" |
| 76 | + git push |
0 commit comments