Skip to content

Latest commit

 

History

History
135 lines (108 loc) · 5.06 KB

README_CN.md

File metadata and controls

135 lines (108 loc) · 5.06 KB

⚡️ Traffic to Badge GitHub Action

sync2gitee traffic2badge Github last commit Github latest release Github license

GitHub views GitHub clones

简体中文 | English

使用存储库 Insights/traffic 数据来生成包含访问数和克隆数的徽章。

注意:它还会将私密的 Insights/traffic 数据备份到 traffic branch 中。

🎨 目录

🚀 使用

input:
  my_token:
    description: '设置个人访问令牌以获取机密存储库流量数据。'
    required: true
  static_list:
    description: '设置一个包含要使用的存储库的列表。'
    required: true
  traffic_branch:
    description: '如果为空,则流量数据将备份到名为 traffic 的分支中。'
    required: false
    default: 'traffic'
  views_color:
    description: '为 views 徽章背景设置一个十六进制或命名的颜色值。'
    required: false
    default: 'brightgreen'
  clones_color:
    description: '为 clones 徽章背景设置一个十六进制或命名的颜色值。'
    required: false
    default: 'brightgreen'
  logo:
    description: '在标签左侧插入命名的徽标或简单图标。'
    required: false
    default: 'github'

📝 示例

本示例使用 peaceiris/[email protected] 将流量数据发布到 traffic branch

name: traffic2badge
on:
  pull_request:
  push:
    branches:
      - main
  schedule:
    # UTC 18:00 -> CST (China) 2:00 see https://datetime360.com/cn/utc-cst-china-time/
    - cron: '1 18 * * *'

jobs:
  run:
    name: Make GitHub Traffic data to Badge
    runs-on: ubuntu-latest
    steps:
      - name: Get current repository name
        id: info
        uses: actions/[email protected]
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          result-encoding: string
          script: |
            return context.repo.repo;

      - name: Set traffic
        uses: yi-Xu-0100/[email protected]
        with:
          my_token: ${{ secrets.TRAFFIC_TOKEN }}
          static_list: '${{ steps.info.outputs.result }}'
          traffic_branch: traffic
          views_color: brightgreen
          clones_color: brightgreen
          logo: github

      - name: Deploy
        uses: peaceiris/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_branch: traffic
          publish_dir: ./traffic
          user_name: 'github-actions[bot]'
          user_email: 'github-actions[bot]@users.noreply.github.com'
          full_commit_message: ${{ github.event.head_commit.message }}

      - name: Show traffic data
        run: |
          cd ./traffic/
          ls -a
          cd ./traffic-${{ steps.info.outputs.result }}/
          ls -a

🙈 生成 my_token

这部分是从 sangonzal/repository-traffic-action 获得的。

首先,您需要创建一个个人访问令牌(PAT),使该操作可以访问 GitHub API

您可以通过转到 Settings(GitHub) -> Developer Settings -> Personal Access Tokens -> Generate new token 来生成 PAT,并且需要授予 repo 权限。 有关更多信息,请参见 GitHub 文档

生成 PAT 后,转到Settings(repository) -> Secrets -> New secret,将 secret 命名为 TRAFFIC_TOKEN,然后将 PAT 复制到框中。

🔊 更新日志

📄 协议

🎉 鸣谢