Skip to content

Commit

Permalink
DOCSP-8882: Add release workflow (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad authored Feb 13, 2020
1 parent 1ff41f4 commit 91c92dc
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 22 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on:
push:
tags:
- 'v*'

name: Create Release

jobs:
build:
name: Upload Release Asset
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build package
id: build_package
run: |
npm install --production
make static
make package-preview
- name: Get environment
id: environment
run: |
echo "::set-output name=date::$(date +%Y-%m-%d)"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: "Release: [${{ github.ref }}] - ${{ steps.environment.outputs.date }}"
draft: true
prerelease: true
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ steps.build_package.outputs.package_filename }}
asset_name: ${{ steps.build_package.outputs.package_filename }}
asset_content_type: application/zip
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
USER=$(shell whoami)
STAGING_URL="https://docs-mongodborg-staging.corp.mongodb.com"
STAGING_BUCKET=docs-mongodb-org-staging
include .env.production
PLATFORM=$(shell printf '%s_%s' "$$(uname -s | tr '[:upper:]' '[:lower:]')" "$$(uname -m)")
PACKAGE_NAME=snooty-preview-${VERSION}-${PLATFORM}.zip
VERSION=$(shell git describe --tags)
-include .env.production

.PHONY: stage static

Expand All @@ -16,6 +19,9 @@ else
PREFIX = $(GATSBY_PARSER_BRANCH)/$(GATSBY_SITE)
endif

package-preview:
zip -9r --symlinks ${PACKAGE_NAME} src node_modules preview preview-start.js static webpack.config.js index.html package.json package-lock.json
echo "::set-output name=package_filename::${PACKAGE_NAME}"

stage: prefix
@if [ -z "${GATSBY_SNOOTY_DEV}" ]; then \
Expand All @@ -31,5 +37,10 @@ static:
-rm -r ./docs-tools/
git submodule add --force https://github.com/mongodb/docs-tools
-mkdir -p ./static/images
mv ./docs-tools/themes/mongodb/static ./static/docs-tools/
mv ./docs-tools/themes/guides/static/images/bg-accent.svg ./static/docs-tools/images/bg-accent.svg
-mkdir -p ./static/docs-tools
cp -a ./docs-tools/themes/mongodb/static/fonts ./static/docs-tools/
cp ./docs-tools/themes/mongodb/static/guides.css ./static/docs-tools/
cp ./docs-tools/themes/mongodb/static/mongodb-docs.css ./static/docs-tools/
cp ./docs-tools/themes/mongodb/static/navbar.min.js ./static/docs-tools/
cp ./docs-tools/themes/mongodb/static/css/navbar.min.css ./static/docs-tools/
cp ./docs-tools/themes/guides/static/images/bg-accent.svg ./static/images/
2 changes: 1 addition & 1 deletion docs-tools
Submodule docs-tools updated 0 files
8 changes: 1 addition & 7 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
const { execSync } = require('child_process');
const userInfo = require('os').userInfo;
const { generatePathPrefix } = require('./src/utils/generate-path-prefix');
const { getGitBranch } = require('./src/utils/get-git-branch');

const runningEnv = process.env.NODE_ENV || 'production';

require('dotenv').config({
path: `.env.${runningEnv}`,
});

const getGitBranch = () => {
return execSync('git rev-parse --abbrev-ref HEAD')
.toString('utf8')
.replace(/[\n\r\s]+$/, '');
};

const metadata = {
parserBranch: process.env.GATSBY_PARSER_BRANCH,
project: process.env.GATSBY_SITE,
Expand Down
68 changes: 61 additions & 7 deletions package-lock.json

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

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "snooty",
"version": "0.1.0",
"version": "0.2.0",
"repository": "github:mongodb/snooty",
"devDependencies": {
"auto-changelog": "^1.16.2",
"babel-jest": "^24.9.0",
"babel-loader": "^8.0.6",
"babel-preset-gatsby": "^0.2.23",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.15.1",
Expand All @@ -23,6 +23,7 @@
"build": "gatsby build --prefix-paths",
"clean": "gatsby clean",
"develop": "gatsby develop",
"ensure-master": "node scripts/ensure-master.js",
"format": "npm run prettier -- --check",
"format:fix": "npm run prettier -- --write",
"lint": "eslint --ignore-path .gitignore --ignore-path .prettierignore --ignore-pattern 'docs-tools/*' --ignore-pattern 'preview/*' --ext .js,.jsx .",
Expand All @@ -32,7 +33,10 @@
"serve": "gatsby serve --prefix-paths",
"test": "jest",
"test:regression": "jest regression",
"test:unit": "jest unit"
"test:unit": "jest unit",
"preversion": "npm run ensure-master && npm run format && npm run lint && npm run test:unit",
"version": "auto-changelog -p --template keepachangelog && git add CHANGELOG.md",
"postversion": "git push origin v$npm_package_version"
},
"lint-staged": {
"*.js": [
Expand All @@ -42,6 +46,7 @@
]
},
"dependencies": {
"babel-loader": "^8.0.6",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.3",
Expand Down
18 changes: 18 additions & 0 deletions scripts/ensure-master.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { getGitBranch } = require('../src/utils/get-git-branch');

const ensureMaster = () => getGitBranch() === 'master';

const main = () => {
let warned = false;

if (!ensureMaster()) {
warned = true;
console.error('Can only release on master');
}

if (warned) {
process.exit(1);
}
};

main();
2 changes: 1 addition & 1 deletion src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const HTML = ({ body, bodyAttributes, headComponents, htmlAttributes, preBodyCom
) : (
<link rel="stylesheet" href={withPrefix('docs-tools/mongodb-docs.css')} type="text/css" />
)}
<link rel="stylesheet" href={withPrefix('docs-tools/css/navbar.min.css')} type="text/css" />
<link rel="stylesheet" href={withPrefix('docs-tools/navbar.min.css')} type="text/css" />
{headComponents}
</head>
<body {...bodyAttributes}>
Expand Down
9 changes: 9 additions & 0 deletions src/utils/get-git-branch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { execSync } = require('child_process');

const getGitBranch = () => {
return execSync('git rev-parse --abbrev-ref HEAD')
.toString('utf8')
.replace(/[\n\r\s]+$/, '');
};

module.exports.getGitBranch = getGitBranch;

0 comments on commit 91c92dc

Please sign in to comment.