Skip to content

Commit cdd50fe

Browse files
committed
misc: update workflows
1 parent 13866a3 commit cdd50fe

File tree

7 files changed

+192
-137
lines changed

7 files changed

+192
-137
lines changed

.github/workflows/changelog.yml

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,75 @@
11
name: Pull request changelog
22

33
on:
4-
pull_request:
5-
types: [opened, synchronize, reopened, labeled, unlabeled]
4+
pull_request_target:
5+
types: [labeled, unlabeled, synchronize]
66

77
jobs:
8-
changelog:
9-
name: 'check changelog change'
8+
check-changelog:
9+
name: 'check changelog'
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- name: Fail if no changelog change when needed
13+
- name: Check if version label is present
14+
id: labels
1415
uses: actions/github-script@v2
1516
with:
1617
github-token: ${{ secrets.GITHUB_TOKEN }}
1718
script: |
18-
const labelsWhereChangelogChangeIsRequired = [
19+
const versionLabels = [
20+
'Action: no bump',
21+
'Action: beta bump',
1922
'Action: patch bump',
2023
'Action: minor bump',
2124
'Action: major bump',
2225
];
23-
const { data: labels } = await github.issues.listLabelsOnIssue({
26+
27+
const { data: pullLabels } = await github.issues.listLabelsOnIssue({
2428
owner: context.repo.owner,
2529
repo: context.repo.repo,
2630
issue_number: context.payload.pull_request.number,
2731
per_page: 100,
2832
});
29-
const matchingLabels = labels
30-
.filter(label => labelsWhereChangelogChangeIsRequired.includes(label.name))
31-
if (matchingLabels.length === 0) {
32-
console.log('::debug ::No label requiring changelog change. Nothing to do')
33+
34+
const labels = pullLabels.map(label => label.name);
35+
36+
const versionLabelsPresent = labels
37+
.filter(name => versionLabels.includes(name));
38+
39+
console.log(`::debug ::${versionLabelsPresent.length} matching labels`);
40+
41+
if (versionLabelsPresent.length !== 1) {
42+
throw new Error('Should have one and only one version bump label');
43+
}
44+
45+
const versionLabel = versionLabelsPresent[0];
46+
console.log(`::set-output name=versionLabel::${versionLabel}`)
47+
48+
if (versionLabel === 'Action: no bump') {
3349
return;
3450
}
51+
52+
- name: Fail if no changelog change when needed
53+
if: |
54+
steps.labels.outputs.versionLabel != 'Action: no bump'
55+
&& steps.labels.outputs.versionLabel != 'Action: beta bump'
56+
uses: actions/github-script@v2
57+
with:
58+
github-token: ${{ secrets.GITHUB_TOKEN }}
59+
script: |
3560
const { data: files } = await github.pulls.listFiles({
3661
owner: context.repo.owner,
3762
repo: context.repo.repo,
3863
pull_number: context.payload.pull_request.number,
3964
per_page: 100,
4065
});
66+
67+
const changelogFile = 'CHANGELOG.md';
68+
4169
const fileNotDeletedNames = files
4270
.filter(file => file.status === 'added' || file.status === 'modified')
43-
.map(file => file.filename)
44-
if (!fileNotDeletedNames.includes('CHANGELOG.md')) {
71+
.map(file => file.filename);
72+
73+
if (!fileNotDeletedNames.includes(changelogFile)) {
4574
throw new Error('CHANGELOG.md Unreleased section shoud have line additions when PR is not a no-release')
4675
}

.github/workflows/deployment.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Deployment
2+
3+
on:
4+
deployment
5+
6+
jobs:
7+
deploy-package:
8+
name: Deploy package
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Update deployment status
13+
uses: actions/github-script@v3
14+
env:
15+
NAME: ${{ github.event.deployment.payload.name }}
16+
VERSION: ${{ github.event.deployment.payload.version }}
17+
DEPLOYMENT_ID: ${{ github.event.deployment.id }}
18+
with:
19+
github-token: ${{ secrets.GITHUB_TOKEN }}
20+
previews: 'ant-man,flash'
21+
script: |
22+
const name = process.env.NAME;
23+
const version = process.env.VERSION;
24+
const cratesUrl = `https://crates.io/crates/${name}/${version}`;
25+
26+
const { data: deploymentStatus } = github.repos.createDeploymentStatus({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
deployment_id: process.env.DEPLOYMENT_ID,
30+
environment_url: cratesUrl,
31+
description: `Publishing ${name}@${version} on crates.io`,
32+
auto_inactive: false,
33+
state: 'in_progress',
34+
});
35+
36+
37+
- name: Checkout code
38+
uses: actions/checkout@v2
39+
with:
40+
ref: ${{ github.event.deployment.payload.ref }}
41+
42+
- name: Git config
43+
run: |
44+
git config user.name "Github actions - Async-graphql"
45+
git config user.email "[email protected]"
46+
47+
- name: Install
48+
uses: actions-rs/toolchain@v1
49+
with:
50+
toolchain: stable
51+
52+
- name: Login
53+
uses: actions-rs/cargo@v1
54+
with:
55+
command: login
56+
args: ${{ secrets.CRATES_IO_API_TOKEN }}
57+
58+
- name: Publish
59+
id: publish
60+
uses: actions-rs/cargo@v1
61+
with:
62+
command: publish
63+
64+
- name: Update deployment status
65+
uses: actions/github-script@v3
66+
env:
67+
NAME: ${{ github.event.deployment.payload.name }}
68+
VERSION: ${{ github.event.deployment.payload.version }}
69+
DEPLOYMENT_ID: ${{ github.event.deployment.id }}
70+
with:
71+
github-token: ${{ secrets.TOKEN_REPO_WRITE }}
72+
previews: 'ant-man,flash'
73+
script: |
74+
const name = process.env.NAME;
75+
const version = process.env.VERSION;
76+
const cratesUrl = `https://crates.io/crates/${name}/${version}`;
77+
78+
const state = 'success';
79+
80+
const { data: deploymentStatus } = github.repos.createDeploymentStatus({
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
deployment_id: process.env.DEPLOYMENT_ID,
84+
environment_url: cratesUrl,
85+
description: `Published ${name}@${version} on crates.io`,
86+
auto_inactive: false,
87+
state,
88+
});

.github/workflows/label.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
name: Pull request labels
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types: [labeled, unlabeled, synchronize]
66

77
jobs:
8-
version-labels:
9-
name: 'check version label'
8+
check-labels:
9+
name: 'check labels'
1010
runs-on: ubuntu-latest
1111

1212
steps:
1313
- name: Check if version label is present
14+
id: version
1415
uses: actions/github-script@v2
1516
with:
1617
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -22,16 +23,23 @@ jobs:
2223
'Action: minor bump',
2324
'Action: major bump',
2425
];
26+
2527
const { data: labels } = await github.issues.listLabelsOnIssue({
2628
owner: context.repo.owner,
2729
repo: context.repo.repo,
2830
issue_number: context.payload.pull_request.number,
2931
per_page: 100,
3032
});
33+
3134
const versionLabelsPresent = labels
3235
.filter(label => versionLabels.includes(label.name))
36+
3337
if (versionLabelsPresent.length === 1) {
38+
console.log(`::set-output name=versionLabel::${versionLabelsPresent[0].name}`)
3439
return;
3540
}
41+
3642
console.log(`::debug ::${versionLabelsPresent.length} matching labels`);
43+
3744
throw new Error(`Should have one and only one of ${versionLabels.join(', ')} labels`);
45+

.github/workflows/on-merge.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ jobs:
6060
- name: Bumb classic version
6161
if: steps.extract-version-label.outputs.versionBump != 'beta'
6262
env:
63-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6463
BUMP_TYPE: ${{ steps.extract-version-label.outputs.versionBump }}
6564
run: |
6665
npm install -g semver
@@ -119,7 +118,7 @@ jobs:
119118
id: extract-changelog
120119
if: steps.extract-version-label.outputs.versionBump != 'beta'
121120
run: |
122-
VERSION=$(cat package.json | jq -r '.version')
121+
VERSION=$(cat Cargo.toml | grep "version" | head -n 1 | cut -d'"' -f2)
123122
VERSION_PART=$(sed -n "/## \[$VERSION\]/,/## \[/{/## \[/d;p;}" CHANGELOG.md)
124123
VERSION_PART="${VERSION_PART//'%'/'%25'}"
125124
VERSION_PART="${VERSION_PART//$'\n'/'%0A'}"

.github/workflows/on-publish.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)