Skip to content

Commit

Permalink
ci: Add generation of changelog (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Sep 17, 2023
1 parent b534f73 commit 64d4ff2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions scripts/gen-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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<string> {
const { version } = packageJSON;
Expand Down Expand Up @@ -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',
},
Expand Down

0 comments on commit 64d4ff2

Please sign in to comment.