Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add generation of changelog #367

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading