Skip to content

Commit bb600da

Browse files
committed
feat: add semantic release
1 parent f7cd542 commit bb600da

8 files changed

Lines changed: 263 additions & 1 deletion
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Continuous Deployment
2+
3+
on:
4+
push:
5+
branches:
6+
- 'release'
7+
8+
env:
9+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10+
GIT_EMAIL: ${{ secrets.GIT_EMAIL }}
11+
12+
jobs:
13+
build:
14+
name: Build and deploy app
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
20+
- name: Read .nvmrc
21+
id: nvmrc
22+
run: echo "::set-output name=node::$(cat .nvmrc)"
23+
24+
- name: Use Node.js ${{ steps.nvmrc.outputs.node }}
25+
uses: actions/setup-node@v2
26+
with:
27+
node-version: ${{ steps.nvmrc.outputs.node }}
28+
29+
- name: Read npm cache
30+
uses: actions/cache@v2
31+
with:
32+
path: ~/.npm
33+
key: node-cache-${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
34+
restore-keys: |
35+
node-cache-${{ runner.os }}-npm-
36+
37+
- name: Install packages
38+
run: npm ci
39+
40+
- name: Lint
41+
run: npm run lint
42+
43+
- name: Build
44+
run: npx semantic-release

.github/workflows/continuous-integration.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: Continuous Integration
22

3-
on: [push]
3+
on:
4+
push:
5+
branches-ignore:
6+
- 'release'
7+
pull_request:
8+
branches:
9+
- '*'
410

511
jobs:
612
build:

.releaserc.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"branches": ["release"],
3+
"plugins": [
4+
[
5+
"@semantic-release/commit-analyzer",
6+
{
7+
"releaseRules": [
8+
{
9+
"type": "chore",
10+
"release": "patch"
11+
}
12+
]
13+
}
14+
],
15+
"@semantic-release/release-notes-generator",
16+
"@semantic-release/changelog",
17+
"@semantic-release/npm",
18+
"@semantic-release/git",
19+
[
20+
"@semantic-release/exec",
21+
{
22+
"prepareCmd": "./tools/package-google-cloud-sql.sh ${nextRelease.version}"
23+
}
24+
],
25+
[
26+
"@semantic-release/github",
27+
{
28+
"assets": [
29+
{
30+
"path": "bin/google-cloud-sql-linux.tar.gz",
31+
"name": "google-cloud-sql-linux-${nextRelease.version}.tar.gz",
32+
"label": "Linux distribution"
33+
},
34+
{
35+
"path": "bin/google-cloud-sql-macos.tar.gz",
36+
"name": "google-cloud-sql-macos-${nextRelease.version}.tar.gz",
37+
"label": "MacOS distribution"
38+
},
39+
{
40+
"path": "bin/google-cloud-sql-win.tar.gz",
41+
"name": "google-cloud-sql-win-${nextRelease.version}.tar.gz",
42+
"label": "Windows distribution"
43+
}
44+
]
45+
}
46+
],
47+
[
48+
"@semantic-release/exec",
49+
{
50+
"prepareCmd": "./tools/publish-brew-formula.sh ${nextRelease.version}"
51+
}
52+
]
53+
]
54+
}

README.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@ See https://www.npmjs.com/package/pkg#targets[pkg] for details.
8181
----
8282
npx pkg <NODE_RANGE>-<PLATFORM>-<ARCH>
8383
----
84+
85+
== Deploy
86+
To deploy a new version of `google-cloud-sql` app, merge `master` branch into `release` branch.

package-lock.json

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"exec:dev": "ts-node src/index.ts",
2525
"exec:dist": "node dist/index.js",
2626
"lint": "eslint . --ext .ts",
27+
"test": "npm run lint",
2728
"prepare": "husky install",
2829
"prettify-package-json": "prettier-package-json --write"
2930
},
@@ -40,6 +41,9 @@
4041
"shelljs": "0.8.5"
4142
},
4243
"devDependencies": {
44+
"@semantic-release/changelog": "6.0.1",
45+
"@semantic-release/exec": "6.0.3",
46+
"@semantic-release/git": "10.0.1",
4347
"@tsconfig/node16": "1.0.2",
4448
"@types/inquirer": "8.1.3",
4549
"@types/inquirer-autocomplete-prompt": "1.3.3",

tools/package-google-cloud-sql.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
version="$1"
4+
5+
npx replace-in-file '0.0.0-dev' "$version" ./src/lib/version.ts
6+
npm run bundle
7+
8+
cd bin
9+
tar --transform s/-linux// -czf "google-cloud-sql-linux.tar.gz" google-cloud-sql-linux
10+
tar --transform s/-macos// -czf "google-cloud-sql-macos.tar.gz" google-cloud-sql-macos
11+
tar --transform s/-win// -czf "google-cloud-sql-win.tar.gz" google-cloud-sql-win.exe
12+
cd ..

tools/publish-brew-formula.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
version="$1"
4+
url="https://github.com/edosrecki/google-cloud-sql-cli/releases/download/v$version/google-cloud-sql-macos-$version.tar.gz"
5+
checksum=$(shasum -a 256 bin/google-cloud-sql-macos.tar.gz | awk '{ print $1 }')
6+
7+
git clone "https://${GITHUB_TOKEN}@github.com/edosrecki/homebrew-tools.git"
8+
cd homebrew-tools
9+
10+
git config user.email "${GIT_EMAIL}"
11+
git config user.name "Dinko Osrecki"
12+
13+
cat <<EOF > google-cloud-sql.rb
14+
class GoogleCloudSql < Formula
15+
desc ""
16+
homepage "https://github.com/edosrecki/google-cloud-sql-cli"
17+
url "$url"
18+
sha256 "$checksum"
19+
bottle :unneeded
20+
def install
21+
bin.install "google-cloud-sql"
22+
end
23+
test do
24+
system "#{bin}/google-cloud-sql", "--version"
25+
end
26+
end
27+
EOF
28+
29+
git add google-cloud-sql.rb
30+
git commit -m "chore: release google-cloud-sql v$version"
31+
git push
32+
33+
cd ..
34+
rm -rf homebrew-tools

0 commit comments

Comments
 (0)