diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml new file mode 100644 index 00000000..8bfad6a5 --- /dev/null +++ b/.github/workflows/changelog.yml @@ -0,0 +1,35 @@ +name: CI +on: workflow_call +permissions: {} +jobs: + generateChangelog: + name: Generate changelog + runs-on: ubuntu-latest + permissions: + contents: read # for actions/checkout + steps: + - name: Checkout repo + uses: actions/checkout@v3 + with: + persist-credentials: false + fetch-depth: 0 # fetch all history + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + cache: npm + node-version-file: '.node-version' + + - name: Install Dependencies + run: npm ci --ignore-scripts + + - name: Generate changelog + run: npm run changelog > changelog.txt + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload npm folder + uses: actions/upload-artifact@v3 + with: + name: changelog + path: ./changelog.txt diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b169df10..808cba33 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,11 +11,18 @@ jobs: security-events: write # for codeql-action uses: ./.github/workflows/ci.yml + changelog: + permissions: + contents: read # for actions/checkout + uses: ./.github/workflows/changelog.yml + npm-publish: environment: name: npm-publish url: https://www.npmjs.com/package/graphql-voyager/v/${{github.ref_name}} - needs: ci + needs: + - ci + - changelog permissions: contents: read # for actions/checkout runs-on: ubuntu-latest diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 98caf85b..3540e9b6 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -8,6 +8,11 @@ jobs: security-events: write # for codeql-action uses: ./.github/workflows/ci.yml + changelog: + permissions: + contents: read # for actions/checkout + uses: ./.github/workflows/changelog.yml + deploy-to-gh-pages: name: Deploy to GitHub Pages needs: ci diff --git a/scripts/gen-changelog.ts b/scripts/gen-changelog.ts index 19796a42..19f8bdcc 100644 --- a/scripts/gen-changelog.ts +++ b/scripts/gen-changelog.ts @@ -31,10 +31,10 @@ const labelsConfig: { [label: string]: { section: string; fold?: boolean } } = { fold: true, }, }; -const { GH_TOKEN } = process.env; +const { GITHUB_TOKEN } = process.env; -if (GH_TOKEN == null) { - console.error('Must provide GH_TOKEN as environment variable!'); +if (GITHUB_TOKEN == null) { + console.error('Must provide GITHUB_TOKEN as environment variable!'); process.exit(1); } @@ -55,7 +55,10 @@ const { githubOrg, githubRepo } = repoURLMatch.groups; genChangeLog() .then((result) => process.stdout.write(result)) - .catch((e) => console.error(e)); + .catch((e) => { + console.error(e); + process.exit(1); + }); async function genChangeLog(): Promise { const { version } = packageJSON; @@ -136,7 +139,7 @@ async function graphqlRequest(query: string) { const response = await fetch('https://api.github.com/graphql', { method: 'POST', headers: { - Authorization: 'bearer ' + GH_TOKEN, + Authorization: 'bearer ' + GITHUB_TOKEN, 'Content-Type': 'application/json', 'User-Agent': 'gen-changelog', },