Skip to content

Commit

Permalink
Build: handle release builds (#95)
Browse files Browse the repository at this point in the history
Add non-internal-release (release) builds, which run on release infrastructure.

---------

Co-authored-by: Seth Foster <[email protected]>
  • Loading branch information
dapiroy and sfoster1 authored Aug 10, 2023
1 parent b376966 commit 49b1047
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .github/actions/build-refs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ outputs:
description: "the ref of the ot3-firmware to use"
build-type:
description: "the type of build oe-core will create (develop, release)"
variant:
description: "internal-release or release"
runs:
using: 'node16'
main: 'dist/index.js'
48 changes: 47 additions & 1 deletion .github/actions/build-refs/action/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as action from '../index'
import type { InputRefs, Ref, Branch, BuildType } from '../index'
import type { InputRefs, Ref, Branch, BuildType, Variant } from '../index'

const AUTHORITATIVE_REF_TEST_SPECS: Array<
[string, InputRefs, [string, boolean]]
Expand Down Expand Up @@ -153,3 +153,49 @@ BUILD_TYPE_TEST_SPECS.forEach(
})
}
)

const VARIANT_TEST_SPECS: Array<[string, Ref, Variant]> = [
[
'when monorepo ref is a general branch name',
'refs/heads/some-random-branch',
'release',
],
['when monorepo ref is edge', 'refs/heads/edge', 'release'],
['when monorepo ref is release branch', 'refs/heads/main', 'release'],
[
'when monorepo ref is a release candidate branch',
'refs/heads/release_7.1.0',
'release',
],
[
'when monorepo ref is a release candidate branch with old style name',
'refs/heads/chore_release-8.1.0',
'release',
],
[
'when monorepo ref is an internal-release branch',
'refs/heads/internal-release',
'internal-release',
],
[
'when monorepo ref is an internal-release candidate branch',
'refs/heads/internal-release_0.165.0',
'internal-release',
],
['when monorepo ref is a release tag', 'refs/tags/v123.213.8', 'release'],
[
'when monorepo ref is an internal-release tag',
'refs/tags/[email protected]',
'internal-release',
],
]

VARIANT_TEST_SPECS.forEach(
([testNameFragment, testMonorepoRef, testExpectedResult]) => {
test(`variant ${testNameFragment}`, () => {
expect(action.variantForRef(testMonorepoRef)).toStrictEqual(
testExpectedResult
)
})
}
)
28 changes: 26 additions & 2 deletions .github/actions/build-refs/action/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as core from '@actions/core'

export type Repo = 'oe-core' | 'monorepo' | 'ot3-firmware'
export type BuildType = 'develop' | 'release'

export type Variant = 'internal-release' | 'release'
const orderedRepos: Repo[] = ['monorepo', 'oe-core', 'ot3-firmware']

export type Branch = string
Expand Down Expand Up @@ -35,6 +35,22 @@ export interface GitHubApiTag {
ref: Tag
}

export function variantForRef(ref: Ref): Variant {
if (ref.startsWith('refs/heads')) {
if (ref.includes('internal-release')) {
return 'internal-release'
} else {
return 'release'
}
} else if (ref.startsWith('refs/tags')) {
if (ref.includes('ot3@')) {
return 'internal-release'
} else if (ref.startsWith('refs/tags/v')) {
return 'release'
}
}
return 'internal-release'
}
function latestTagPrefixFor(repo: Repo): string {
if (repo === 'monorepo') return 'refs/tags/v'
if (repo === 'oe-core') return 'refs/tags/v'
Expand Down Expand Up @@ -181,7 +197,7 @@ async function resolveRefs(toAttempt: AttemptableRefs): Promise<OutputRefs> {
resolved.set(
repo,
await Promise.all(refList.map(ref => refResolves(repo, ref))).then(
presentRefs => presentRefs.find(maybeRef => maybeRef !== null)
presentRefs => presentRefs.find(maybeRef => maybeRef !== null) || null
)
)
}
Expand Down Expand Up @@ -216,14 +232,22 @@ async function run() {

const resolved = await resolveRefs(attemptable)
resolved.forEach((ref, repo) => {
if (!ref) {
throw new Error(
`Could not resolve ${repo} input reference ${inputs.get(repo)}`
)
}
core.info(`Resolved ${repo} to ${ref}`)
core.setOutput(repo, ref)

// Determine the build-type based on the monorepo ref
if (repo === 'monorepo') {
const buildType = resolveBuildType(ref)
const variant = variantForRef(ref)
core.info(`Resolved oe-core build-type to ${buildType}`)
core.setOutput('build-type', buildType)
core.setOutput('variant', variant)
core.info(`Resolved oe-core variant to ${variant}`)
}
})
}
Expand Down
28 changes: 27 additions & 1 deletion .github/actions/build-refs/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9728,6 +9728,7 @@ var __webpack_exports__ = {};
__nccwpck_require__.r(__webpack_exports__);
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
/* harmony export */ "restAPICompliantRef": () => (/* binding */ restAPICompliantRef),
/* harmony export */ "variantForRef": () => (/* binding */ variantForRef),
/* harmony export */ "latestTag": () => (/* binding */ latestTag),
/* harmony export */ "authoritativeRef": () => (/* binding */ authoritativeRef),
/* harmony export */ "refsToAttempt": () => (/* binding */ refsToAttempt),
Expand Down Expand Up @@ -9759,6 +9760,25 @@ function mainRefFor(input) {
function restAPICompliantRef(input) {
return input.replace('refs/', '');
}
function variantForRef(ref) {
if (ref.startsWith('refs/heads')) {
if (ref.includes('internal-release')) {
return 'internal-release';
}
else {
return 'release';
}
}
else if (ref.startsWith('refs/tags')) {
if (ref.includes('ot3@')) {
return 'internal-release';
}
else if (ref.startsWith('refs/tags/v')) {
return 'release';
}
}
return 'internal-release';
}
function latestTagPrefixFor(repo) {
if (repo === 'monorepo')
return 'refs/tags/v';
Expand Down Expand Up @@ -9859,7 +9879,7 @@ function resolveRefs(toAttempt) {
return availableRefs.includes(correctRef) ? correctRef : null;
});
});
resolved.set(repo, yield Promise.all(refList.map(ref => refResolves(repo, ref))).then(presentRefs => presentRefs.find(maybeRef => maybeRef !== null)));
resolved.set(repo, yield Promise.all(refList.map(ref => refResolves(repo, ref))).then(presentRefs => presentRefs.find(maybeRef => maybeRef !== null) || null));
}
return resolved;
});
Expand All @@ -9885,13 +9905,19 @@ function run() {
});
const resolved = yield resolveRefs(attemptable);
resolved.forEach((ref, repo) => {
if (!ref) {
throw new Error(`Could not resolve ${repo} input reference ${inputs.get(repo)}`);
}
_actions_core__WEBPACK_IMPORTED_MODULE_1__.info(`Resolved ${repo} to ${ref}`);
_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput(repo, ref);
// Determine the build-type based on the monorepo ref
if (repo === 'monorepo') {
const buildType = resolveBuildType(ref);
const variant = variantForRef(ref);
_actions_core__WEBPACK_IMPORTED_MODULE_1__.info(`Resolved oe-core build-type to ${buildType}`);
_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput('build-type', buildType);
_actions_core__WEBPACK_IMPORTED_MODULE_1__.setOutput('variant', variant);
_actions_core__WEBPACK_IMPORTED_MODULE_1__.info(`Resolved oe-core variant to ${variant}`);
}
});
});
Expand Down
70 changes: 47 additions & 23 deletions .github/workflows/build-ot3-actions.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Build OT3 internal-release image on github workflows'
name: 'Build Flex image on github workflows'
run-name: 'image: mono ${{ inputs.monorepo-ref }}, core ${{ inputs.oe-core-ref }}, fw ${{ inputs.ot3-firmware-ref }}'
on:
workflow_dispatch:
Expand Down Expand Up @@ -30,19 +30,20 @@ on:
default: 'stage-prod'

jobs:
run-build:
strategy:
matrix:
build_env: [ '${{ inputs.infra-stage }}' ]
name: 'Building images on ${{ matrix.build_env }}'
timeout-minutes: 480
runs-on: ['self-hosted', '${{matrix.build_env}}']
decide-refs:
runs-on: ubuntu-latest
outputs:
oe-core: ${{ steps.build-refs.outputs.oe-core }}
monorepo: ${{ steps.build-refs.outputs.monorepo }}
ot3-firmware: ${{ steps.build-refs.outputs.ot3-firmware }}
variant: ${{ steps.build-refs.outputs.variant }}
build-type: ${{ steps.build-refs.outputs.build-type }}
name: 'deciding refs to build'
steps:
- name: Fetch initial sources for action
uses: 'actions/checkout@v3'
with:
submodules: false
fetch-depth: 0
path: ./oe-core-for-workflow
- name: Decide refs to build
id: build-refs
Expand All @@ -52,25 +53,40 @@ jobs:
monorepo: ${{ inputs.monorepo-ref }}
oe-core: ${{ inputs.oe-core-ref }}
ot3-firmware: ${{ inputs.ot3-firmware-ref }}
run-build:
needs: decide-refs
strategy:
matrix:
build_env: [ '${{ inputs.infra-stage }}' ]
name: 'Building ${{needs.decide-refs.outputs.variant}} images on ${{ matrix.build_env }}'
timeout-minutes: 480
runs-on: ['self-hosted', '${{matrix.build_env}}', '${{needs.decide-refs.outputs.variant}}']
steps:
- name: Fetch initial sources for action
uses: 'actions/checkout@v3'
with:
submodules: false
fetch-depth: 0
path: ./oe-core-for-workflow
- name: Fetch oe-core source
uses: 'actions/checkout@v3'
with:
submodules: false
fetch-depth: 0
ref: ${{steps.build-refs.outputs.oe-core}}
ref: ${{needs.decide-refs.outputs.oe-core}}
path: ./oe-core
- name: Fetch monorepo source
uses: 'actions/checkout@v3'
with:
fetch-depth: 0
ref: ${{ steps.build-refs.outputs.monorepo }}
ref: ${{ needs.decide-refs.outputs.monorepo }}
repository: Opentrons/opentrons
path: ./opentrons
- name: Fetch ot3-firmware source
uses: 'actions/checkout@v3'
with:
fetch-depth: 0
ref: ${{ steps.build-refs.outputs.ot3-firmware }}
ref: ${{ needs.decide-refs.outputs.ot3-firmware }}
repository: Opentrons/ot3-firmware
path: ./ot3-firmware
- name: Sync oe-core submodules
Expand Down Expand Up @@ -103,10 +119,10 @@ jobs:
echo 'DL_DIR = "/volumes/cache/downloads"' >> ./build/conf/local.conf
echo 'GITDIR = "/volumes/cache/git"' >> ./build/conf/local.conf
echo 'SSTATE_DIR = "/volumes/cache/sstate"' >> ./build/conf/local.conf
echo 'OT_BUILD_TYPE = "${{steps.build-refs.outputs.build-type}}"' >> ./build/conf/local.conf
echo 'OT_BUILD_TYPE = "${{needs.decide-refs.outputs.build-type}}"' >> ./build/conf/local.conf
echo 'YARN_CACHE_DIR = "/volumes/cache/yarn"' >> ./build/conf/local.conf
echo 'ELECTRON_CACHE_DIR = "/volumes/cache/electron"' >> ./build/conf/local.conf
echo 'OPENTRONS_PROJECT = "ot3"' >> ./build/conf/local.conf
echo 'OPENTRONS_PROJECT = "${{needs.decide-refs.outputs.variant == 'release' && 'robot-stack' || 'ot3'}}"' >> ./build/conf/local.conf
# setup signing key
echo 'SIGNING_KEY = "${TOPDIR}/.signing-key"' >> ./build/conf/local.conf
cat <<EOF >./build/.signing-key
Expand Down Expand Up @@ -194,9 +210,9 @@ jobs:
tar czf ${_artifact_s3}/buildstats.tar.gz ${_oe_tmp}/buildstats
mkdir -p ${_artifact_versioned}
_fulltag="${{steps.build-refs.outputs.monorepo}}"
_fulltag="${{needs.decide-refs.outputs.monorepo}}"
echo "monorepo_shorttag=${_fulltag:10}" >> $GITHUB_OUTPUT
_vers_suffix="${_fulltag:14}"
_vers_suffix=${{needs.decide-refs.outputs.variant == 'release' && '${_fulltag:11}' || '${_fulltag:14}'}}
_system_zipname="ot3-system-${_vers_suffix}.zip"
_version_jsonname="VERSION-${_vers_suffix}.json"
_fullimage_tarname="ot3-fullimage-${_vers_suffix}.tar"
Expand All @@ -211,7 +227,7 @@ jobs:
echo "artifact_unversioned_subdir=${_artifact_unversioned_subdir}" >> $GITHUB_OUTPUT
echo "artifact_versioned=${_artifact_versioned}" >> $GITHUB_OUTPUT
- name: Handle Release
if: ${{ steps.build-refs.outputs.build-type == 'release' }}
if: ${{ needs.decide-refs.outputs.build-type == 'release' }}
shell: bash
id: 'handle-release'
run: |
Expand All @@ -236,7 +252,7 @@ jobs:
echo "fullimage_url=$root_url/ot3-fullimage.tar" >> $GITHUB_OUTPUT
popd
- name: Upload system zip to monorepo release
if: steps.build-refs.outputs.build-type == 'release'
if: needs.decide-refs.outputs.build-type == 'release'
uses: 'ncipollo/[email protected]'
with:
allowUpdates: true
Expand All @@ -250,7 +266,7 @@ jobs:
artifactContentType: application/zip
token: ${{secrets.MONOREPO_RELEASE_ARTIFACT_UPLOAD_TOKEN}}
- name: Upload fullimage tar to monorepo release
if: steps.build-refs.outputs.build-type == 'release'
if: needs.decide-refs.outputs.build-type == 'release'
uses: 'ncipollo/[email protected]'
with:
allowUpdates: true
Expand All @@ -264,7 +280,7 @@ jobs:
artifactContentType: application/x-tar
token: ${{secrets.MONOREPO_RELEASE_ARTIFACT_UPLOAD_TOKEN}}
- name: Upload version json to monorepo release
if: steps.build-refs.outputs.build-type == 'release'
if: needs.decide-refs.outputs.build-type == 'release'
uses: 'ncipollo/[email protected]'
with:
allowUpdates: true
Expand All @@ -277,13 +293,21 @@ jobs:
artifacts: ${{ steps.artifacts.outputs.versioned_version_json }}
artifactContentType: application/json
token: ${{secrets.MONOREPO_RELEASE_ARTIFACT_UPLOAD_TOKEN}}
- name: Post results
if: ${{ matrix.build_env == 'stage-prod' }}
- name: Post results as internal-release
if: ${{ matrix.build_env == 'stage-prod' && needs.decide-refs.outputs.variant=='internal-release' }}
uses: slackapi/[email protected]
with:
payload: "{\"s3-url\":\"${{ steps.upload-results.outputs.console_url }}/\",\"type\":\"branch\", \"reflike\":\"${{ steps.build-refs.outputs.oe-core }}\",\"monorepo-reflike\":\"${{ steps.build-refs.outputs.monorepo }}\",\"firmware-reflike\":\"${{ steps.build-refs.outputs.ot3-firmware }}\",\"full-image\":\"${{ steps.upload-results.outputs.fullimage_url }}\", \"system-update\":\"${{ steps.upload-results.outputs.system_url }}\", \"version-file\":\"${{ steps.upload-results.outputs.version_file_url }}\", \"release-notes\":\"${{ steps.upload-results.outputs.release_notes_file_url }}\"}"
payload: "{\"s3-url\":\"${{ steps.upload-results.outputs.console_url }}/\",\"type\":\"branch\", \"reflike\":\"${{ needs.decide-refs.outputs.oe-core }}\",\"monorepo-reflike\":\"${{ needs.decide-refs.outputs.monorepo }}\",\"firmware-reflike\":\"${{ needs.decide-refs.outputs.ot3-firmware }}\",\"full-image\":\"${{ steps.upload-results.outputs.fullimage_url }}\", \"system-update\":\"${{ steps.upload-results.outputs.system_url }}\", \"version-file\":\"${{ steps.upload-results.outputs.version_file_url }}\", \"release-notes\":\"${{ steps.upload-results.outputs.release_notes_file_url }}\"}"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

- name: Post results as release
if: ${{ matrix.build_env == 'stage-prod' && needs.decide-refs.outputs.variant== 'release' }}
uses: slackapi/[email protected]
with:
payload: "{\"s3-url\":\"${{ steps.upload-results.outputs.console_url }}/\",\"type\":\"branch\", \"reflike\":\"${{ needs.decide-refs.outputs.oe-core }}\",\"monorepo-reflike\":\"${{ needs.decide-refs.outputs.monorepo }}\",\"firmware-reflike\":\"${{ needs.decide-refs.outputs.ot3-firmware }}\",\"full-image\":\"${{ steps.upload-results.outputs.fullimage_url }}\", \"system-update\":\"${{ steps.upload-results.outputs.system_url }}\", \"version-file\":\"${{ steps.upload-results.outputs.version_file_url }}\", \"release-notes\":\"${{ steps.upload-results.outputs.release_notes_file_url }}\"}"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_RELEASE }}
- name: Remove build data
if: always()
run: |
Expand Down

0 comments on commit 49b1047

Please sign in to comment.