Closed14

Franklin.jlでドキュメント生成でプレビューを有効化する

HyrodiumHyrodium

https://github.com/JuliaPackageComparisons/JuliaPackageComparisons.github.io/issues/56 に対処したい。やりたいこと:

  • PRが作成されると自動的にドキュメント生成してpushする
  • push先は同リポジトリ(JuliaPackageComparisons/JuliaPackageComparisons.github.io)ではなく、別のリポジトリ(JuliaPackageComparisons/preview など)とする
  • forkからでも正常に動いて欲しい
  • Previewがdeployされればpreview用のURLを自動的に投稿して欲しい
HyrodiumHyrodium

試したこと

Forkしたhyrodium/JuliaPackageComparisons.github.ioでの作業

新しくOrganization作成して作業

HyrodiumHyrodium

forkありのPRでドキュメントdeploy失敗しているのはシークレットを参照できていないのが問題っぽい

pull_requestではなくpull_request_targetで発火させるとscecretにアクセスできて良いが、実行するコードもfork元を参照してしまうので面倒っぽい…?

ChatGPTに聞いても、セキュリティ的な懸念を沢山並べるだけで実際のコードの提案が疎かになりがちだったりする。俺の聞き方が悪いのか…?自然言語に落として丁寧に質問するのも疲れてしまう感覚がある。

HyrodiumHyrodium

fork無しのPRでもコメント投稿に失敗しているのが謎。

https://github.com/HyrodiumOrg/HyrodiumOrg.github.io/pull/3 で色々試してみたが、どうも上手く行かない。公式ドキュメントに従って

    - name: Create comment
      uses: peter-evans/create-or-update-comment@v4
      with:
        issue-number: 1
        body: |
          This is a multi-line test comment
          - With GitHub **Markdown** :sparkles:
          - Created by [create-or-update-comment][1]

          [1]: https://github.com/peter-evans/create-or-update-comment
        reactions: '+1'

のように設定してみたが

Run peter-evans/create-or-update-comment@v4
  with:
    issue-number: 1
    body: This is a multi-line test comment
  - With GitHub **Markdown** :sparkles:
  - Created by [create-or-update-comment][1]
  
  [1]: https://github.com/peter-evans/create-or-update-comment
  
    reactions: +1
    token: ***
    repository: HyrodiumOrg/HyrodiumOrg.github.io
    edit-mode: append
    append-separator: newline
    reactions-edit-mode: append
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.8.18/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.8.18/x64/lib
    SSH_AUTH_SOCK: /tmp/ssh-XXXXXXMw11bp/agent.2250
    SSH_AGENT_PID: 2251
    deployment_status: skipped
/home/runner/work/_actions/peter-evans/create-or-update-comment/v4/dist/index.js:4695
      const error = new requestError.RequestError(toErrorMessage(data), status, {
                    ^

RequestError [HttpError]: Resource not accessible by integration
    at /home/runner/work/_actions/peter-evans/create-or-update-comment/v4/dist/index.js:4695:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 403,
  response: {
    url: 'https://api.github.com/repos/HyrodiumOrg/HyrodiumOrg.github.io/issues/1/comments',
    status: 403,
    headers: {
      'access-control-allow-origin': '*',
      'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
      'content-encoding': 'gzip',
      'content-security-policy': "default-src 'none'",
      'content-type': 'application/json; charset=utf-8',
      date: 'Sat, 27 Jan 2024 05:08:23 GMT',
      'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
      server: 'GitHub.com',
      'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
      'transfer-encoding': 'chunked',
      vary: 'Accept-Encoding, Accept, X-Requested-With',
      'x-accepted-github-permissions': 'issues=write; pull_requests=write',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'deny',
      'x-github-api-version-selected': '2022-11-28',
      'x-github-media-type': 'github.v3; format=json',
      'x-github-request-id': '5C40:961E:106A7CE:21A7887:65B48FC7',
      'x-ratelimit-limit': '1000',
      'x-ratelimit-remaining': '995',
      'x-ratelimit-reset': '1706332859',
      'x-ratelimit-resource': 'core',
      'x-ratelimit-used': '5',
      'x-xss-protection': '0'
    },
    data: {
      message: 'Resource not accessible by integration',
      documentation_url: 'https://docs.github.com/rest/issues/comments#create-an-issue-comment'
    }
  },
  request: {
    method: 'POST',
    url: 'https://api.github.com/repos/HyrodiumOrg/HyrodiumOrg.github.io/issues/1/comments',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit-core.js/3.6.0 Node.js/20.8.1 (linux; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: '{"body":"This is a multi-line test comment\\n- With GitHub **Markdown** :sparkles:\\n- Created by [create-or-update-comment][1]\\n\\n[1]: https://github.com/peter-evans/create-or-update-comment"}',
    request: {
      agent: Agent {
        _events: [Object: null prototype] {
          free: [Function (anonymous)],
          newListener: [Function: maybeEnableKeylog]
        },
        _eventsCount: 2,
        _maxListeners: undefined,
        defaultPort: 443,
        protocol: 'https:',
        options: [Object: null prototype] {
          keepAlive: true,
          scheduling: 'lifo',
          timeout: 5000,
          noDelay: true,
          path: null
        },
        requests: [Object: null prototype] {},
        sockets: [Object: null prototype] {},
        freeSockets: [Object: null prototype] {
          'api.github.com:443:::::::::::::::::::::': [ [TLSSocket] ]
        },
        keepAliveMsecs: 1000,
        keepAlive: true,
        maxSockets: Infinity,
        maxFreeSockets: 256,
        scheduling: 'lifo',
        maxTotalSockets: Infinity,
        totalSocketCount: 1,
        maxCachedSessions: 100,
        _sessionCache: {
          map: {
            'api.github.com:443:::::::::::::::::::::': [Buffer [Uint8Array]]
          },
          list: [ 'api.github.com:443:::::::::::::::::::::' ]
        },
        [Symbol(kCapture)]: false
      },
      hook: [Function: bound bound register]
    }
  }
}

Node.js v20.8.1

のエラーが発生。
類似のissueがいくつかあったが(#188, #212, #238)、あまり参考にならなかった。
つまり

  • Forkから実行している訳ではないのでシークレットが使えない訳ではない
  • リポジトリへのアクセス権限も問題無さそう

HyrodiumHyrodium

はい解決、pull-requests: writeの設定不足でした。

https://github.com/HyrodiumOrg/HyrodiumOrg.github.io/pull/3#issuecomment-1913088276

公式ドキュメントより:

You can use permissions to modify the default permissions granted to the GITHUB_TOKEN,

github actionsの「permissions」とはなにか?のメモが良かった。感謝。

GitHub ActionsでNGを検出した際にPRにコメントをする方法の記事などを読んで、permissionsの設定どうなってたっけ?と思って気づいた次第。ところでcreate-or-update-commentのREADMEにpermissionsについて記載が無くて不親切な気がした。

HyrodiumHyrodium

GITHUB_TOKENを雰囲気で使いすぎてただけだったな……。

HyrodiumHyrodium

次はforkからpreview生成ジョブが実行できるようにやっていき!

このスクラップは3ヶ月前にクローズされました