Update setup-repo.yml #5
This file contains hidden or 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: Setup Repository Metadata | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - '.github/workflows/setup-repo.yml' | |
| jobs: | |
| setup-metadata: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Extract Repository Info | |
| id: extract | |
| run: | | |
| echo "REPO_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_OUTPUT | |
| NAME_PARTS=$(echo "${GITHUB_REPOSITORY#*/}" | tr '_' '\n') | |
| echo "${NAME_PARTS}" | nl | |
| echo "TOPICS=[]" > topics.json | |
| mapfile -t parts <<< "$NAME_PARTS" | |
| # Predefined base topics | |
| BASE_TOPICS=("template") | |
| for word in ${NAME_PARTS}; do | |
| BASE_TOPICS+=("$(echo $word | tr '[:upper:]' '[:lower:]')") | |
| done | |
| echo "TOPICS=$(jq -nc --argjson arr "$(printf '%s\n' "${BASE_TOPICS[@]}" | jq -R . | jq -s .)" '$arr')" >> $GITHUB_OUTPUT | |
| - name: Print Extracted Info | |
| run: | | |
| echo "Repo Name: ${{ steps.extract.outputs.REPO_NAME }}" | |
| echo "Topics: ${{ steps.extract.outputs.TOPICS }}" | |
| - name: Set Repository Topics | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.PAT_TOKEN }} | |
| script: | | |
| const repo = context.repo.repo; | |
| const owner = context.repo.owner; | |
| const topics = JSON.parse(`${{ steps.extract.outputs.TOPICS }}`); | |
| await github.rest.repos.replaceAllTopics({ | |
| owner, | |
| repo, | |
| names: topics | |
| }); | |
| console.log(`Topics set for ${repo}:`, topics); |