Skip to content

Commit bc5ae97

Browse files
authored
pull from dev (#50)
<!-- markdownlint-disable first-line-h1 no-inline-html --> <!-- Hidden Markdown: Do Not Update this Area. In order to have the best experience with our community, we recommend that you read the code of conduct and contributing guidelines before submitting a pull request. By submitting this pull request, you confirm that you have read, understood, and agreed to the project's code of conduct and contributing guidelines. Please use conventional commits to format the title of the pull request and the commit messages. For more information, please refer to https://www.conventionalcommits.org. -->. ### Summary <!-- Hidden Markdown: Do Not Update this Area. Please provide a clear and concise description of the pull request. -->. ### Type <!-- Hidden Markdown: Do Not Update this Area. Please check the one(s) that applies to this pull request using "x". --> - [ ] Bugfix - [ ] Enhancement or Feature - [ ] Code Style or Formatting - [ ] Documentation - [ ] Refactoring - [ ] Chore - [ ] Other Please describe:. ### Breaking Changes? <!-- Hidden Markdown: Do Not Update this Area. Please check the one that applies to this pull request using "x". If this pull request contains a breaking change, please describe the impact and mitigation path. --> - [ ] Yes, there are breaking changes. - [ ] No, there are no breaking changes.. ### Test and Documentation <!-- Hidden Markdown: Do Not Update this Area. Please check the one(s) that applies to this pull request using "x". For bug fixes and enhancements/features, please ensure that tests and documentation have been completed and provide details. --> - [ ] Tests have been completed. - [ ] Documentation has been added or updated. <!-- Hidden Markdown: Do Not Update this Area. Please describe the tests that have been completed and/or the documentation that has been added/updated. -->. ### Issue References <!-- Hidden Markdown: Do Not Update this Area. Is this related to any GitHub issue(s)? If so, please provide the issue number(s) that are closed or resolved by this pull request. For bug fixes and enhancements/features, please ensure that a GitHub issue has been created and provide the issue number(s) here. Please use the 'Closes' keyword followed by the a hash and issue number. This will link the pull request to the issue(s) and automatically close them when the pull request is merged. Example: Closes #000 Closes #1 -->. ### Additional Information <!-- Hidden Markdown: Do Not Update this Area. Please provide any additional information that may be helpful. -->
2 parents 6379968 + 916a90c commit bc5ae97

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

.github/workflows/clone.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,41 @@ name: GitHub Clone Count Update Everyday
22

33
on:
44
schedule:
5-
- cron: "0 0 * * *"
5+
- cron: 0 0 * * *
66
workflow_dispatch:
77

88
jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
permissions:
12+
# Required to commit CLONE.md file to repository
13+
# Note: contents: write is the minimal permission needed for this workflow
14+
# trunk-ignore(checkov): contents: write is required to commit files to repository
1215
contents: write
1316

1417
steps:
1518
- uses: actions/checkout@v6
19+
with:
20+
ref: ${{ github.ref }}
21+
fetch-depth: 0
22+
token: ${{ secrets.SECRET_TOKEN }}
1623

1724
- name: gh login
1825
run: echo "${{ secrets.SECRET_TOKEN }}" | gh auth login --with-token
1926

2027
- name: parse latest clone count
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.SECRET_TOKEN }}
2130
run: |
2231
set -euo pipefail
23-
if ! curl -f --user "${{ github.actor }}:${{ secrets.SECRET_TOKEN }}" \
32+
# SECRET_TOKEN is required because:
33+
# 1. The traffic/clones endpoint requires "Administration" (read) permissions
34+
# 2. GITHUB_TOKEN typically doesn't have access to traffic data
35+
# 3. A Personal Access Token (PAT) with repo scope is needed
36+
# Using environment variable to avoid exposing secret in process list
37+
# Note: Secret is passed via env var, not command line, for security
38+
# trunk-ignore(trufflehog): Secret properly handled via environment variable, not command line
39+
if ! curl -f --user "${{ github.actor }}:$GITHUB_TOKEN" \
2440
-H "Accept: application/vnd.github.v3+json" \
2541
"https://api.github.com/repos/${{ github.repository }}/traffic/clones" \
2642
> clone.json; then
@@ -110,12 +126,15 @@ jobs:
110126
json.dump(latest, fh, ensure_ascii=False, indent=4)
111127
EOF
112128
- name: Update gist with latest count
129+
env:
130+
GITHUB_TOKEN: ${{ secrets.SECRET_TOKEN }}
113131
run: |
114132
set -euo pipefail
133+
# Using environment variable to avoid exposing secret in process list
115134
content=$(sed -e 's/\\/\\\\/g' -e 's/\t/\\t/g' -e 's/\"/\\"/g' -e 's/\r//g' "clone.json" | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')
116135
echo '{"description": "${{ github.repository }} clone statistics", "files": {"clone.json": {"content": "'"$content"'"}}}' > post_clone.json
117136
if ! curl -f -s -X PATCH \
118-
--user "${{ github.actor }}:${{ secrets.SECRET_TOKEN }}" \
137+
--user "${{ github.actor }}:$GITHUB_TOKEN" \
119138
-H "Content-Type: application/json" \
120139
-d @post_clone.json "https://api.github.com/gists/${{ steps.set_id.outputs.GIST }}" > /dev/null; then
121140
echo "Error: Failed to update gist"
@@ -139,5 +158,7 @@ jobs:
139158
- name: Push
140159
uses: ad-m/github-push-action@master
141160
with:
142-
github_token: ${{ secrets.GITHUB_TOKEN }}
161+
github_token: ${{ secrets.SECRET_TOKEN }}
162+
branch: "gh-actions"
163+
force_with_lease: true
143164

CLONE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
**Markdown**
3+
```markdown
4+
[![GitHub Clones](https://img.shields.io/badge/dynamic/json?color=success&label=Clone&query=count&url=https://gist.githubusercontent.com/nathanthaler/7879c8fd9af27b17da21abe20eedee1d/raw/clone.json&logo=github)](https://gist.githubusercontent.com/nathanthaler/7879c8fd9af27b17da21abe20eedee1d/raw/clone.json)
5+
```

0 commit comments

Comments
 (0)