Skip to content

Commit dbc2568

Browse files
committed
#25: Add in some DevOps scripts and update as needed
1 parent 13a5718 commit dbc2568

File tree

6 files changed

+626
-12
lines changed

6 files changed

+626
-12
lines changed

.github/workflows/release.yml

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
name: Package and Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 'preview/**'
8+
tags:
9+
- test*
10+
- v*
11+
12+
jobs:
13+
package-x64:
14+
runs-on: ubuntu18.04
15+
env:
16+
TERM: xterm
17+
strategy:
18+
node-version:
19+
- '14'
20+
21+
steps:
22+
# Install deps and cache
23+
# Eventually it would be great if these steps could live in a separate YAML file
24+
# that could be included in line to avoid code duplication
25+
- name: Checkout code
26+
uses: actions/checkout@v2
27+
with:
28+
fetch-depth: 0
29+
- name: Install node ${{ matrix.node-version }}
30+
uses: actions/setup-node@v2
31+
with:
32+
node-version: ${{ matrix.node-version }}
33+
- name: Get Yarn cache directory
34+
id: yarn-cache-dir-path
35+
run: echo "::set-output name=dir::$(yarn cache dir)"
36+
- name: Use Yarn cache
37+
id: yarn-cache
38+
uses: actions/cache@v2
39+
with:
40+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
41+
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
42+
- name: Install Yarn dependencies
43+
run: yarn install --prefer-offline --frozen-lockfile
44+
45+
# Package and upload the cli
46+
# @NOTE: We cross-compile on Linux because _right now_ this seems to be
47+
# the only place we can reliably build all the variants. We use actions/upload
48+
# so move assets between jobs
49+
- name: Package ${{ matrix.variant }} CLI
50+
run: |
51+
node ./scripts/dev-version.js
52+
node ./bin/lando.js version
53+
yarn pkg --target=node${{ matrix.node-version }}-${{ matrix.variant }} --no-version
54+
- name: Upload lando-build-${{ matrix.variant }}-${{ github.sha }}
55+
uses: actions/upload-artifact@v2
56+
with:
57+
name: lando-build-${{ matrix.variant }}-${{ github.sha }}
58+
path: dist/
59+
if-no-files-found: error
60+
retention-days: 1
61+
62+
package-arm64:
63+
runs-on: ${{ matrix.os }}
64+
env:
65+
TERM: xterm
66+
strategy:
67+
matrix:
68+
os:
69+
- ubuntu-20.04
70+
node-version:
71+
- '14'
72+
73+
steps:
74+
# Install deps and cache
75+
# Eventually it would be great if these steps could live in a separate YAML file
76+
# that could be included in line to avoid code duplication
77+
- name: Checkout code
78+
uses: actions/checkout@v2
79+
with:
80+
fetch-depth: 0
81+
- name: Install node ${{ matrix.node-version }}
82+
uses: actions/setup-node@v2
83+
with:
84+
node-version: ${{ matrix.node-version }}
85+
- name: Get Yarn cache directory
86+
id: yarn-cache-dir-path
87+
run: echo "::set-output name=dir::$(yarn cache dir)"
88+
- name: Use Yarn cache
89+
id: yarn-cache
90+
uses: actions/cache@v2
91+
with:
92+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
93+
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
94+
- name: Install Yarn dependencies
95+
run: yarn install --prefer-offline --frozen-lockfile
96+
97+
# Package and upload the cli
98+
# @NOTE: We cross-compile on Linux because _right now_ this seems to be
99+
# the only place we can reliably build all the variants. We use actions/upload
100+
# so move assets between jobs
101+
- name: Package ${{ matrix.variant }} CLI
102+
run: |
103+
node ./scripts/dev-version.js
104+
node ./bin/lando.js version
105+
yarn pkg --target=node${{ matrix.node-version }}-${{ matrix.variant }} --no-version
106+
- name: Upload lando-build-${{ matrix.variant }}-${{ github.sha }}
107+
uses: actions/upload-artifact@v2
108+
with:
109+
name: lando-build-${{ matrix.variant }}-${{ github.sha }}
110+
path: dist/
111+
if-no-files-found: error
112+
retention-days: 1
113+
114+
115+
ship-x64:
116+
runs-on: ${{ matrix.os }}
117+
needs:
118+
- package-x64
119+
env:
120+
TERM: xterm
121+
strategy:
122+
matrix:
123+
os:
124+
- macos-10.15
125+
- ubuntu-20.04
126+
- windows-2019
127+
arch:
128+
- x64
129+
- arm64
130+
exclude:
131+
- os: windows-2019
132+
arch: arm64
133+
steps:
134+
# Set things up for signing, notarizing, uploading etc
135+
- name: Checkout code
136+
uses: actions/checkout@v2
137+
with:
138+
fetch-depth: 0
139+
- name: Set other variables
140+
id: vars
141+
shell: bash
142+
run: |
143+
# Set generic source ref vars
144+
echo "::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/}"
145+
echo "::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/}"
146+
echo "::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/}"
147+
# Unset vars if it makes sense to do so
148+
if [ "$GITHUB_REF" == "${GITHUB_REF#refs/tags/}" ]; then echo "::set-output name=SOURCE_TAG::"; fi
149+
if [ "$GITHUB_REF" == "${GITHUB_REF#refs/heads/}" ]; then echo "::set-output name=SOURCE_BRANCH::"; fi
150+
151+
# Set os specific vars
152+
if [ "$RUNNER_OS" == "Linux" ]; then
153+
echo '::set-output name=OS::linux'
154+
echo '::set-output name=PKG_ENDING::'
155+
elif [ "$RUNNER_OS" == "Windows" ]; then
156+
echo '::set-output name=OS::win'
157+
echo '::set-output name=PKG_ENDING::.exe'
158+
else
159+
echo '::set-output name=OS::macos'
160+
echo '::set-output name=PKG_ENDING::'
161+
fi
162+
- name: Set SOURCE_PKG
163+
id: pkg
164+
shell: bash
165+
run: echo '::set-output name=SOURCE_PKG::lando-${{ steps.vars.outputs.OS }}-${{ matrix.arch }}${{ steps.vars.outputs.PKG_ENDING }}'
166+
- name: Test user defined variables
167+
shell: bash
168+
run: |
169+
echo "The OS is ${{ steps.vars.outputs.OS }}"
170+
echo "The SOURCE_NAME is ${{ steps.vars.outputs.SOURCE_NAME }}"
171+
echo "The SOURCE_BRANCH is ${{ steps.vars.outputs.SOURCE_BRANCH }}"
172+
echo "The SOURCE_TAG is ${{ steps.vars.outputs.SOURCE_TAG }}"
173+
echo "The SOURCE_PKG is ${{ steps.pkg.outputs.SOURCE_PKG }}"
174+
- name: Download lando-build-${{ steps.vars.outputs.OS }}-${{ matrix.arch }}-${{ github.sha }}
175+
uses: actions/download-artifact@v2
176+
with:
177+
name: lando-build-${{ steps.vars.outputs.OS }}-${{ matrix.arch }}-${{ github.sha }}
178+
path: dist
179+
180+
# Codesign macOS binaries
181+
# NOTE: We cannot currently do this on macOS because of below issue
182+
# https://github.com/vercel/pkg/issues/128
183+
# However, the logic is here and ready to go once that is resolved
184+
# NOTE: We also should add notarization logic here?
185+
- name: Codesign macOS binaries
186+
env:
187+
APPLE_CERT_DATA: ${{ secrets.APPLE_CERT_DATA }}
188+
APPLE_CERT_PASSWORD: ${{ secrets.APPLE_CERT_PASSWORD }}
189+
APPLE_TEAM_ID: FY8GAUX282
190+
if: ${{ steps.vars.outputs.OS == 'macos' }}
191+
run: |
192+
./scripts/sign-macos.sh ./dist/${{ steps.pkg.outputs.SOURCE_PKG }}
193+
echo "::warning:: Codesign currently disabled because of https://github.com/vercel/pkg/issues/128"
194+
# Codesign WiNdOzE binaries
195+
- name: Codesign Windoze binaries
196+
env:
197+
WINDOZE_CERT_DATA: ${{ secrets.WINDOZE_CERT_DATA }}
198+
WINDOZE_CERT_PASSWORD: ${{ secrets.WINDOZE_CERT_PASSWORD }}
199+
if: ${{ steps.vars.outputs.OS == 'win' }}
200+
shell: powershell
201+
run: ./scripts/sign-win.ps1 ./dist/${{ steps.pkg.outputs.SOURCE_PKG }}
202+
203+
# Depending on the type of commit eg tagged, etc create the releases we need
204+
- name: Create releases
205+
env:
206+
SOURCE_BRANCH: ${{ steps.vars.outputs.SOURCE_BRANCH }}
207+
SOURCE_TAG: ${{ steps.vars.outputs.SOURCE_TAG }}
208+
PKG_PREFIX: "lando-${{ steps.vars.outputs.OS }}-${{ matrix.arch }}"
209+
PKG_SUFFIX: ${{ steps.vars.outputs.PKG_ENDING }}
210+
shell: bash
211+
run: |
212+
# Create release directories
213+
mkdir -p ./releases ./dev-builds
214+
215+
# Snapshot release
216+
cp -f ./dist/${{ steps.pkg.outputs.SOURCE_PKG }} "./dev-builds/$PKG_PREFIX-build-${{ github.sha }}$PKG_SUFFIX"
217+
218+
# Branch releases
219+
if [ -z "$SOURCE_TAG" ]; then cp -f ./dist/${{ steps.pkg.outputs.SOURCE_PKG }} "./releases/$PKG_PREFIX-$SOURCE_BRANCH-latest$PKG_SUFFIX"; fi
220+
# Latest dev release
221+
if [[ "$SOURCE_BRANCH" == "main" ]]; then cp -f ./dist/${{ steps.pkg.outputs.SOURCE_PKG }} "./releases/$PKG_PREFIX-latest$PKG_SUFFIX"; fi
222+
# Tag releases
223+
if [ ! -z "$SOURCE_TAG" ]; then cp -f ./dist/${{ steps.pkg.outputs.SOURCE_PKG }} "./releases/$PKG_PREFIX-$SOURCE_TAG$PKG_SUFFIX"; fi
224+
# Latest stable release
225+
if [ ! -z "$SOURCE_TAG" ]; then cp -f ./dist/${{ steps.pkg.outputs.SOURCE_PKG }} "./releases/$PKG_PREFIX-stable$PKG_SUFFIX"; fi
226+
227+
# Print what we end up with
228+
ls -lsa ./releases
229+
ls -lsa ./dev-builds
230+
231+
# Replace previously posted unsigned raw artifacts with signed build snapshots
232+
- name: Remove unsigned artifacts
233+
uses: geekyeggo/delete-artifact@v1
234+
with:
235+
name: lando-build-${{ steps.vars.outputs.OS }}-${{ matrix.arch }}-${{ github.sha }}
236+
- name: Upload build snapshot as Actions artifact
237+
uses: actions/upload-artifact@v2
238+
with:
239+
name: lando-${{ steps.vars.outputs.OS }}-${{ matrix.arch }}-${{ github.sha }}${{ steps.vars.outputs.PKG_ENDING }}
240+
path: dev-builds/
241+
if-no-files-found: error
242+
retention-days: 30
243+
# Upload releases to S3
244+
- name: Configure S3 Credentials
245+
uses: aws-actions/configure-aws-credentials@v1
246+
with:
247+
aws-access-key-id: ${{ secrets.S3_ACCESS_KEY_ID }}
248+
aws-secret-access-key: ${{ secrets.S3_SECRET_ACCESS_KEY }}
249+
aws-region: us-east-1
250+
- name: Upload releases to S3
251+
shell: bash
252+
run: |
253+
aws s3 sync ./releases s3://files.lando.dev/cli --acl public-read
254+
# Upload releases to GitHub Releases
255+
- name: Upload releases to GitHub Releases
256+
uses: softprops/action-gh-release@v1
257+
if: startsWith(github.ref, 'refs/tags/')
258+
env:
259+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
260+
with:
261+
draft: true
262+
files: ./releases/lando-${{ steps.vars.outputs.OS }}-${{ matrix.arch }}-${{ steps.vars.outputs.SOURCE_TAG }}${{ steps.vars.outputs.PKG_ENDING }}
263+
# @TODO: Handle autochangelog stuff here eventaully
264+
# body_path: ${{ github.workflow }}-CHANGELOG.txt

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@lando/hyperdrive",
3-
"description": "A cli utility for Lando dependency and package management.",
3+
"description": "A library and cli for Lando dependency and package management.",
44
"version": "0.7.0",
55
"author": "Mike Pirog @pirog",
66
"bin": {
7-
"hyperdrive": "./bin/run"
7+
"hyperdrive": "./bin/hyperdrive"
88
},
99
"bugs": "https://github.com/lando/hyperdrive/issues",
1010
"dependencies": {
@@ -13,13 +13,17 @@
1313
"@oclif/plugin-help": "^3"
1414
},
1515
"devDependencies": {
16+
"@oclif/errors": "^1.3.5",
1617
"@oclif/test": "^1",
1718
"chai": "^4",
19+
"cli-ux": "^5.6.3",
1820
"command-line-test": "^1.0.10",
1921
"eslint": "^5.13",
2022
"eslint-config-oclif": "^3.1",
23+
"execa": "^5.1.1",
2124
"globby": "^10",
2225
"leia-parser": "^0.4.0",
26+
"lodash": "^4.17.21",
2327
"mocha": "^5",
2428
"nyc": "^14",
2529
"pkg": "^5.3.1",

scripts/dev-version.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env node
2+
3+
/*
4+
* This is a nifty cross platform script that will replace relevant versions
5+
* in json files with a "dev" version generated with `git describe`
6+
*/
7+
8+
'use strict';
9+
10+
// Grab needed modules
11+
const _ = require('lodash');
12+
const {cli} = require('cli-ux');
13+
const execa = require('execa');
14+
const fs = require('fs');
15+
const handler = require('@oclif/errors/handle');
16+
17+
// Start our sacred promise
18+
execa('git', ['describe', '--tags', '--always', '--abbrev=1'])
19+
20+
// Trim the tag
21+
.then(data => _.trim(data.stdout.slice(1)))
22+
23+
// Replace the version for our files
24+
.then(version => {
25+
const packageJson = require('./../package.json');
26+
packageJson.version = version;
27+
cli.action.start(`Updating package.json to dev version ${packageJson.version}`);
28+
fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2));
29+
return cli.wait(_.random(1000, 3000));
30+
})
31+
32+
// Flag success
33+
.then(() => cli.action.stop())
34+
35+
// Catch errors and do stuff so we can break builds when this fails
36+
.catch(error => handler(error));

scripts/sign-macos.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# Get our file
4+
FILE="$(pwd)/$1"
5+
6+
# Throw error if file does not exist
7+
if [ ! -f "$FILE" ]; then
8+
echo "$FILE does not exist!"
9+
exit 1
10+
fi
11+
12+
# Verify we have the envvars we need
13+
if [ -z "$APPLE_CERT_DATA" ]; then
14+
echo "APPLE_CERT_DATA needs to be set with a base64 encoded p12!"
15+
exit 2
16+
fi
17+
if [ -z "$APPLE_CERT_PASSWORD" ]; then
18+
echo "APPLE_CERT_PASSWORD needs to be set with your p12 password!"
19+
exit 3
20+
fi
21+
if [ -z "$APPLE_TEAM_ID" ]; then
22+
echo "APPLE_TEAM_ID needs to be set with your cert user id!"
23+
exit 4
24+
fi
25+
26+
# Export certs
27+
echo "$APPLE_CERT_DATA" | base64 --decode > /tmp/certs.p12
28+
29+
# Create keychain
30+
security create-keychain -p actions macos-build.keychain
31+
security default-keychain -s macos-build.keychain
32+
security unlock-keychain -p actions macos-build.keychain
33+
security set-keychain-settings -t 3600 -u macos-build.keychain
34+
35+
# Import certs to keychain
36+
security import /tmp/certs.p12 -k ~/Library/Keychains/macos-build.keychain -P "$APPLE_CERT_PASSWORD" -T /usr/bin/codesign -T /usr/bin/productsign
37+
# Key signing
38+
security set-key-partition-list -S apple-tool:,apple: -s -k actions macos-build.keychain
39+
# Verify the things
40+
security find-identity -v macos-build.keychain | grep "$APPLE_TEAM_ID" | grep "Developer ID Application"
41+
42+
# NOTE: We cannot currently do this on macOS because of below issue
43+
# https://github.com/vercel/pkg/issues/128
44+
# However, the logic is here and ready to go once that is resolved
45+
# codesign --force --options runtime -s "$APPLE_TEAM_ID" "$FILE" || true
46+
# @TODO: verify the codesignature

0 commit comments

Comments
 (0)