Last active
November 8, 2024 13:40
-
-
Save Soecka/82f16978f39228e1ef852f30bd48a855 to your computer and use it in GitHub Desktop.
Update repository about fields with github action
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: CI & CD | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- package.json | |
jobs: | |
Build-and-Publish: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
id-token: write | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
env: | |
HOME_PAGE: ${{github.repositoryUrl}} | |
TOPICS: idea2app,agile,devops,cloud,it-transformation,efficient,github,open-source,automation | |
DESCRIPTION: Industry-wide IT transformation expert | |
- name: get content | |
run: | | |
DESCRIPTION=$(node -p "JSON.parse(require('fs').readFileSync('package.json')).description || ''") | |
HOME_PAGE=$(node -p "JSON.parse(require('fs').readFileSync('package.json')).homepage || ''") | |
TOPICS=$(node -p "JSON.parse(require('fs').readFileSync('package.json')).keywords?.join(',').toLowerCase() || ''") | |
[[ "$DESCRIPTION" ]] && gh repo edit "$REPOSITORY" --description "$DESCRIPTION" | |
[[ "$HOME_PAGE" ]] && gh repo edit "$REPOSITORY" --homepage "$HOME_PAGE" | |
[[ "$TOPICS" ]] && { | |
gh api --method PUT "repos/$REPOSITORY/topics" -f "names[]" | |
gh repo edit "$REPOSITORY" --add-topic "$TOPICS" | |
} | |
env: | |
# "Administration" repository permissions (write), https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#replace-all-repository-topics | |
GH_TOKEN: ${{ secrets.ADMIN_TOKEN }} | |
REPOSITORY: ${{ github.repository }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/a/18469304/17588235
https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#replace-all-repository-topics
ADMIN_TOKEN: