Skip to content

Commit

Permalink
chore: add releases.json manifest for app (#13603)
Browse files Browse the repository at this point in the history
This adds a file that lives in the deploy bucket that tracks past
releases of the app. We can use this for autogenerating previous-release
pages and is a good thing to have. We can also use it for release
revocation if we want.
  • Loading branch information
sfoster1 authored Sep 28, 2023
1 parent b8309e7 commit 1879b24
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/app-test-build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ jobs:
- name: 'deploy internal-release release builds to s3'
run: |
aws s3 --profile=deploy sync --acl=public-read to_upload_internal-release/ s3://${{ env._APP_DEPLOY_BUCKET_OT3 }}/${{ env._APP_DEPLOY_FOLDER_OT3 }}
- name: 'upload windows artifacts to GH release'
uses: 'ncipollo/[email protected]'
if: needs.determine-build-type.outputs.type == 'release'
Expand Down Expand Up @@ -412,3 +413,53 @@ jobs:
env:
SLACK_WEBHOOK_URL: ${{ secrets.OT_APP_ROBOTSTACK_SLACK_NOTIFICATION_WEBHOOK_URL }}
_ACCESS_URL: https://${{env._APP_DEPLOY_BUCKET_ROBOTSTACK}}/${{env._APP_DEPLOY_FOLDER_ROBOTSTACK}}

- name: 'pull repo for scripts'
uses: 'actions/checkout@v3'
with:
path: ./monorepo
# https://github.com/actions/checkout/issues/290
- name: 'Fix actions/checkout odd handling of tags'
if: startsWith(github.ref, 'refs/tags')
run: |
cd ./monorepo
git fetch -f origin ${{ github.ref }}:${{ github.ref }}
git checkout ${{ github.ref }}
- uses: 'actions/setup-node@v3'
with:
node-version: '16'
- name: 'install udev'
run: sudo apt-get update && sudo apt-get install libudev-dev
- name: 'set complex environment variables'
id: 'set-vars'
uses: actions/github-script@v6
with:
script: |
const { buildComplexEnvVars } = require(`${process.env.GITHUB_WORKSPACE}/monorepo/.github/workflows/utils.js`)
buildComplexEnvVars(core, context)
- name: 'cache yarn cache'
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/.npm-cache/_prebuild
${{ github.workspace }}/.yarn-cache
key: js-${{ secrets.GH_CACHE_VERSION }}-${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- name: 'setup-js'
run: |
npm config set cache ${{ github.workspace }}/.npm-cache
yarn config set cache-folder ${{ github.workspace }}/.yarn-cache
cd monorepo
make setup-js
- name: 'update internal-releases releases.json'
if: needs.determine-build-type.outputs.type == 'release' && contains(fromJSON(needs.determine-build-type.outputs.variants), 'internal-release')
run: |
aws --profile=deploy s3 cp s3://${{ env._APP_DEPLOY_BUCKET_OT3 }}/${{ env._APP_DEPLOY_FOLDER_OT3 }}/releases.json ./to_upload_internal-release/releases.json
node ./monorepo/scripts/update-releases-json ./to_upload_internal-release/releases.json ot3 ./to_upload_internal-release https://ot3-development.builds.opentrons.com/app/
aws --profile=deploy s3 cp ./to_upload_internal-release/releases.json s3://${{ env._APP_DEPLOY_BUCKET_OT3 }}/${{ env._APP_DEPLOY_FOLDER_OT3 }}/releases.json
- name: 'update release releases.json'
if: needs.determine-build-type.outputs.type == 'release' && contains(fromJSON(needs.determine-build-type.outputs.variants), 'release')
run: |
aws --profile=deploy s3 cp s3://${{ env._APP_DEPLOY_BUCKET_ROBOTSTACK }}/${{ env._APP_DEPLOY_FOLDER_ROBOTSTACK }}/releases.json ./to_upload_release/releases.json
node ./monorepo/scripts/update-releases-json ./to_upload_release/releases.json robot-stack ./to_upload_release https://builds.opentrons.com/app/
aws --profile=deploy s3 cp ./to_upload_release/releases.json s3://${{ env._APP_DEPLOY_BUCKET_ROBOTSTACK }}/${{ env._APP_DEPLOY_FOLDER_ROBOTSTACK }}/releases.json
90 changes: 90 additions & 0 deletions scripts/update-releases-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
'use strict'

const fs = require('fs/promises')

// Updates a releases historical manifest with a release's version.

const versionFinder = require('./git-version')

const parseArgs = require('./deploy/lib/parseArgs')
const USAGE =
'\nUsage:\n node ./scripts/update-releases-json <releases-json-path> <project> <artifact-dir> <url-base>'

async function readOrDefaultReleases(releasesPath) {
try {
const releasesFile = await fs.readFile(releasesPath)
return JSON.parse(releasesFile)
} catch (error) {
console.log(`Could not read releases file: ${error}, defaulting`)
return { production: {} }
}
}

const FILES_IN_RELEASE_JSON = [
/Opentrons.*\.exe$/,
/Opentrons.*\.dmg$/,
/Opentrons.*\.AppImage$/,
/latest.*yml$/,
/alpha.*yml$/,
/beta.*yml$/,
]

function artifactNameToObj(artifactName, urlBase) {
if (artifactName.search(/Opentrons.*\.exe$/) !== -1) {
return { 'Opentrons.exe': urlBase + artifactName }
} else if (artifactName.search(/Opentrons.*\.dmg$/) !== -1) {
return { 'Opentrons.dmg': urlBase + artifactName }
} else if (artifactName.search(/Opentrons.*\.AppImage$/) !== -1) {
return { 'Opentrons.AppImage': urlBase + artifactName }
} else if (artifactName.search(/(latest|alpha|beta).*yml$/) !== -1) {
return { [artifactName]: urlBase + artifactName }
} else {
throw new Error(`Unmatched artifact ${artifactName}`)
}
}

async function artifactsFromDir(artifactDirPath, urlBase) {
const files = await fs.readdir(artifactDirPath, { withFileTypes: true })
return files
.filter(
dirent =>
dirent.isFile() &&
FILES_IN_RELEASE_JSON.some(re => dirent.name.search(re) !== -1)
)
.map(dirent => artifactNameToObj(dirent.name, urlBase))
.reduce((prev, current) => ({ ...prev, ...current }), {})
}

async function main() {
const { args } = parseArgs(process.argv.slice(2))
const [releasesPath, project, artifactDirPath, urlBase] = args
if (!releasesPath || !project || !artifactDirPath || !urlBase) {
throw new Error(USAGE)
}
console.log(`Updating ${releasesPath} with artifacts from ${artifactDirPath}`)
const releasesData = await readOrDefaultReleases(releasesPath)
const version = await versionFinder.versionForProject(project)
console.log(`Adding data for ${version}`)
releasesData.production[version] = {
...(await artifactsFromDir(
artifactDirPath,
urlBase.endsWith('/') ? urlBase : `${urlBase}/`
)),
revoked: false,
}
console.log(
`Added ${Object.keys(releasesData.production[version]).length} artifacts`
)
;(await fs.open(releasesPath, 'w')).writeFile(JSON.stringify(releasesData))
}

if (require.main === module) {
main()
.then(() => {
console.log('release file updated')
})
.catch(error => {
console.error('Release file update failed:', error.message)
process.exitCode = -1
})
}

0 comments on commit 1879b24

Please sign in to comment.