No meu github, durante a execução da criação do comentário no github apareceu o seguinte erro:
Error: Error: Forbidden
at file:///home/runner/work/github-actions/github-actions/scripts/pullRequestPreview.js:45:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Todo o restante do código aparenta funcionar corretamente, porém parece que meu GITHUB_TOKEN não tem permissões para adicionar um comentário no pull-request, mas eu não sei onde eu posso arrumar essas configurações.
Segue o código relacionado a aula:
ci.yml
name: "CI (Integração Contínua): Main Workflow"
env:
# Necessario gerar um token na vercel
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.PROJECT_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
on:
pull_request:
branches: [ "main" ]
jobs:
linter:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
# Roda a instalação das dependências do projeto
- name: Run Installation
run: npm install
# Roda um comando simples usando o shell de execução
- name: Run Linter
run: npm run lint
preview:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
# Roda a instalação das dependências do projeto
- name: Run Installation
run: npm install
# Roda um comando simples usando o shell de execução, o comando gera um preview do site fora de produção com o deploy:staging
- name: Run Preview Deployment
run: npm run deploy:preview
pullRequestPreview
import { execSync } from "child_process";
console.log("[DEPLOY_PREVIEW]: START");
const command = "npm run deploy:staging ";
const output = execSync(command, { encoding: "utf-8" });
const outputLines = output.split("\n");
const DEPLOY_URl = outputLines[outputLines.length - 1];
console.log("[DEPLOY_PREVIEW]: END");
console.log(`You can see the deploly preview on: ${DEPLOY_URl}`);
console.log("[GITHUB_COMMENT]: START");
const { GITHUB_TOKEN, GITHUB_REPOSITORY, GITHUB_PR_NUMBER} = process.env;
console.log("GITHUB_REPOSITORY", GITHUB_REPOSITORY);
console.log("GITHUB_PR_NUMBER", GITHUB_PR_NUMBER);
//HEADER da requisição
const defaultHeaders = {};
defaultHeaders["authorization"] = `token ${GITHUB_TOKEN}`;
defaultHeaders["accept"] =
"application/vnd.github.v3+json; application/vnd.github.antiope-preview+json";
defaultHeaders["content-type"] = "application/json";
const GH_COMMENT = `
- Deploy URL: [${DEPLOY_URl}](${DEPLOY_URl})
`;
fetch(
`https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${GITHUB_PR_NUMBER}/comments`,
{
headers: defaultHeaders,
method: "POST",
body: JSON.stringify({
body: GH_COMMENT,
}),
}
)
.then((response) => {
if (response.ok) return response.json();
throw new Error(response.statusText);
})
.catch((err) => {
console.log("[COMMENT_ON_GITHUB: ERROR]");
throw new Error(err);
})
.finally(() => {
console.log("[COMMENT_ON_GITHUB: END]");
});
Relátorio do action "preview"
Run npm run deploy:preview
> deploy:preview
> node ./scripts/pullRequestPreview.js
[DEPLOY_PREVIEW]: START
Vercel CLI 37.2.1
[DEPLOY_PREVIEW]: END
WARN! `--confirm` is deprecated, please use `--yes` instead
You can see the deploly preview on: https://projeto-curso-ga-teste-nrdpl5pby-henry-kanemotos-projects.vercel.app
The "--no-clipboard" option was ignored because it is the default behavior. Please remove it.
Retrieving project…
Deploying henrykanemoto/projeto-curso-ga-teste
Uploading [--------------------] (0.0B/4.3KB)
Uploading [=====---------------] (1.1KB/4.3KB)
Uploading [==========----------] (2.3KB/4.3KB)
Uploading [====================] (4.3KB/4.3KB)
Inspect: https://vercel.com/henry-kanemotos-projects/projeto-curso-ga-teste/AzPh9AvKWY3dTiRHba1Vxdb7gUsA [2s]
Preview: https://projeto-curso-ga-teste-nrdpl5pby-henry-kanemotos-projects.vercel.app [2s]
Queued
Building
Completing
To deploy to production (projeto-curso-ga-teste-eight.vercel.app), run `vercel --prod`
[GITHUB_COMMENT]: START
GITHUB_REPOSITORY HenryKanemoto/github-actions
GITHUB_PR_NUMBER 5
[COMMENT_ON_GITHUB: ERROR]
[COMMENT_ON_GITHUB: END]
file:///home/runner/work/github-actions/github-actions/scripts/pullRequestPreview.js:45
throw new Error(err);
^
Error: Error: Forbidden
at file:///home/runner/work/github-actions/github-actions/scripts/pullRequestPreview.js:45:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)