Skip to content

Commit b3e19a4

Browse files
committed
feat: add on-merge
1 parent 90dd358 commit b3e19a4

File tree

2 files changed

+115
-1
lines changed

2 files changed

+115
-1
lines changed

.github/workflows/on-merge.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: On merge
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
types: [closed]
7+
8+
jobs:
9+
publish:
10+
name: 'create version and deploy'
11+
runs-on: self-hosted
12+
13+
if: >
14+
github.event.pull_request.merged == true && (
15+
contains(github.event.pull_request.labels.*.name, 'Action: patch bump')
16+
|| contains(github.event.pull_request.labels.*.name, 'Action: minor bump')
17+
|| contains(github.event.pull_request.labels.*.name, 'Action: major bump')
18+
|| contains(github.event.pull_request.labels.*.name, 'Action: beta bump')
19+
)
20+
steps:
21+
- uses: actions/checkout@v2
22+
with:
23+
submodules: recursive
24+
ref: main
25+
token: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- uses: actions/setup-node@v1
28+
with:
29+
node-verion: '12.x'
30+
31+
- name: Git config
32+
run: |
33+
git config user.name "CI Brevz"
34+
git config user.email "[email protected]"
35+
- name: Extract version label
36+
id: extract-version-label
37+
uses: actions/github-script@v2
38+
with:
39+
github-token: ${{ secrets.GITHUB_TOKEN }}
40+
script: |
41+
const versionLabels = {
42+
'Action: patch bump': 'patch',
43+
'Action: minor bump': 'minor',
44+
'Action: major bump': 'major',
45+
'Action: beta bump': 'beta',
46+
};
47+
const versionLabelsNames = Object.keys(versionLabels);
48+
const labels = context.payload.pull_request.labels;
49+
const versionLabelsPresent = labels
50+
.filter(label => versionLabelsNames.includes(label.name))
51+
console.log(`::debug ::${versionLabelsPresent.length} matching labels`);
52+
if (versionLabelsPresent.length > 1) {
53+
throw new Error('Pull request should have only one version label');
54+
}
55+
if (versionLabelsPresent.length === 1) {
56+
const versionBump = versionLabels[versionLabelsPresent[0].name];
57+
console.log(`::set-output name=versionBump::${versionBump}`)
58+
return;
59+
}
60+
- name: Bumb classic version
61+
if: steps.extract-version-label.outputs.versionBump != 'beta'
62+
env:
63+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
64+
BUMP_TYPE: ${{ steps.extract-version-label.outputs.versionBump }}
65+
run: |
66+
npm install -g semver
67+
OLD_VERSION=$(cat Cargo.toml | grep "version" | head -n 1 | cut -d'"' -f2)
68+
NEW_VERSION=$(semver -i $BUMP_TYPE $OLD_VERSION)
69+
sed -i '0,/version.*$/s/version = "'"$OLD_VERSION"'"/version = "'"$NEW_VERSION"'"/' Cargo.toml
70+
npm add --no-save remark-cli@^6.0.0 @jarrodldavis/remark-changelog-version-bump@^0.1.1
71+
./node_modules/.bin/remark CHANGELOG.md -o --use @jarrodldavis/changelog-version-bump=version:\"$NEW_VERSION\"
72+
git add CHANGELOG.md Cargo.toml
73+
git commit -m "$NEW_VERSION"
74+
git tag "v$NEW_VERSION"
75+
- name: Push on main
76+
id: push
77+
run: |
78+
git push
79+
git push --tags
80+
COMMIT_ID=$(git rev-parse HEAD)
81+
echo "::set-output name=ref::$COMMIT_ID"
82+
VERSION=$(cat Cargo.toml | grep "version" | head -n 1 | cut -d'"' -f2)
83+
echo "::set-output name=version::$VERSION"
84+
VERSION=$(cat Cargo.toml | grep "name" | head -n 1 | cut -d'"' -f2)
85+
echo "::set-output name=name::$NAME"
86+
- name: Extract release changelog
87+
id: extract-changelog
88+
if: steps.extract-version-label.outputs.versionBump != 'beta'
89+
run: |
90+
VERSION=$(cat package.json | jq -r '.version')
91+
VERSION_PART=$(sed -n "/## \[$VERSION\]/,/## \[/{/## \[/d;p;}" CHANGELOG.md)
92+
VERSION_PART="${VERSION_PART//'%'/'%25'}"
93+
VERSION_PART="${VERSION_PART//$'\n'/'%0A'}"
94+
VERSION_PART="${VERSION_PART//$'\r'/'%0D'}"
95+
echo VERSION_PART=$VERSION_PART
96+
echo "::set-output name=version-part::$VERSION_PART"
97+
- name: Create Release
98+
if: steps.extract-version-label.outputs.versionBump != 'beta'
99+
uses: actions/github-script@v2
100+
env:
101+
VERSION: ${{ steps.push.outputs.version }}
102+
BODY: ${{ steps.extract-changelog.outputs.version-part }}
103+
with:
104+
github-token: ${{ secrets.GITHUB_TOKEN }}
105+
script: |
106+
await github.repos.createRelease({
107+
owner: context.repo.owner,
108+
repo: context.repo.repo,
109+
tag_name: `v${process.env.VERSION}`,
110+
name: process.env.TAG,
111+
body: process.env.BODY,
112+
draft: false,
113+
prerelease: false,
114+
})

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "async-graphql-extension-apollo-tracing"
3-
version = "0.1.0-beta.0"
3+
version = "0.2.0"
44
authors = ["Anthony Griffon <[email protected]>"]
55
description = "An async_graphql extension to send traces & metrics to Apollo Studio"
66
readme = "README.md"

0 commit comments

Comments
 (0)