Skip to content

Commit

Permalink
feat: add semantic release
Browse files Browse the repository at this point in the history
  • Loading branch information
edosrecki committed Jan 23, 2022
1 parent f7cd542 commit bb600da
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 1 deletion.
44 changes: 44 additions & 0 deletions .github/workflows/continuous-deployment.yml
@@ -0,0 +1,44 @@
name: Continuous Deployment

on:
push:
branches:
- 'release'

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_EMAIL: ${{ secrets.GIT_EMAIL }}

jobs:
build:
name: Build and deploy app
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Read .nvmrc
id: nvmrc
run: echo "::set-output name=node::$(cat .nvmrc)"

- name: Use Node.js ${{ steps.nvmrc.outputs.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ steps.nvmrc.outputs.node }}

- name: Read npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: node-cache-${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
node-cache-${{ runner.os }}-npm-
- name: Install packages
run: npm ci

- name: Lint
run: npm run lint

- name: Build
run: npx semantic-release
8 changes: 7 additions & 1 deletion .github/workflows/continuous-integration.yml
@@ -1,6 +1,12 @@
name: Continuous Integration

on: [push]
on:
push:
branches-ignore:
- 'release'
pull_request:
branches:
- '*'

jobs:
build:
Expand Down
54 changes: 54 additions & 0 deletions .releaserc.json
@@ -0,0 +1,54 @@
{
"branches": ["release"],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{
"type": "chore",
"release": "patch"
}
]
}
],
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git",
[
"@semantic-release/exec",
{
"prepareCmd": "./tools/package-google-cloud-sql.sh ${nextRelease.version}"
}
],
[
"@semantic-release/github",
{
"assets": [
{
"path": "bin/google-cloud-sql-linux.tar.gz",
"name": "google-cloud-sql-linux-${nextRelease.version}.tar.gz",
"label": "Linux distribution"
},
{
"path": "bin/google-cloud-sql-macos.tar.gz",
"name": "google-cloud-sql-macos-${nextRelease.version}.tar.gz",
"label": "MacOS distribution"
},
{
"path": "bin/google-cloud-sql-win.tar.gz",
"name": "google-cloud-sql-win-${nextRelease.version}.tar.gz",
"label": "Windows distribution"
}
]
}
],
[
"@semantic-release/exec",
{
"prepareCmd": "./tools/publish-brew-formula.sh ${nextRelease.version}"
}
]
]
}
3 changes: 3 additions & 0 deletions README.adoc
Expand Up @@ -81,3 +81,6 @@ See https://www.npmjs.com/package/pkg#targets[pkg] for details.
----
npx pkg <NODE_RANGE>-<PLATFORM>-<ARCH>
----

== Deploy
To deploy a new version of `google-cloud-sql` app, merge `master` branch into `release` branch.
105 changes: 105 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -24,6 +24,7 @@
"exec:dev": "ts-node src/index.ts",
"exec:dist": "node dist/index.js",
"lint": "eslint . --ext .ts",
"test": "npm run lint",
"prepare": "husky install",
"prettify-package-json": "prettier-package-json --write"
},
Expand All @@ -40,6 +41,9 @@
"shelljs": "0.8.5"
},
"devDependencies": {
"@semantic-release/changelog": "6.0.1",
"@semantic-release/exec": "6.0.3",
"@semantic-release/git": "10.0.1",
"@tsconfig/node16": "1.0.2",
"@types/inquirer": "8.1.3",
"@types/inquirer-autocomplete-prompt": "1.3.3",
Expand Down
12 changes: 12 additions & 0 deletions tools/package-google-cloud-sql.sh
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

version="$1"

npx replace-in-file '0.0.0-dev' "$version" ./src/lib/version.ts
npm run bundle

cd bin
tar --transform s/-linux// -czf "google-cloud-sql-linux.tar.gz" google-cloud-sql-linux
tar --transform s/-macos// -czf "google-cloud-sql-macos.tar.gz" google-cloud-sql-macos
tar --transform s/-win// -czf "google-cloud-sql-win.tar.gz" google-cloud-sql-win.exe
cd ..
34 changes: 34 additions & 0 deletions tools/publish-brew-formula.sh
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

version="$1"
url="https://github.com/edosrecki/google-cloud-sql-cli/releases/download/v$version/google-cloud-sql-macos-$version.tar.gz"
checksum=$(shasum -a 256 bin/google-cloud-sql-macos.tar.gz | awk '{ print $1 }')

git clone "https://${GITHUB_TOKEN}@github.com/edosrecki/homebrew-tools.git"
cd homebrew-tools

git config user.email "${GIT_EMAIL}"
git config user.name "Dinko Osrecki"

cat <<EOF > google-cloud-sql.rb
class GoogleCloudSql < Formula
desc ""
homepage "https://github.com/edosrecki/google-cloud-sql-cli"
url "$url"
sha256 "$checksum"
bottle :unneeded
def install
bin.install "google-cloud-sql"
end
test do
system "#{bin}/google-cloud-sql", "--version"
end
end
EOF

git add google-cloud-sql.rb
git commit -m "chore: release google-cloud-sql v$version"
git push

cd ..
rm -rf homebrew-tools

0 comments on commit bb600da

Please sign in to comment.