Skip to content

Commit

Permalink
self-builds
Browse files Browse the repository at this point in the history
  • Loading branch information
just-boris committed Mar 28, 2023
1 parent 81e7aaf commit 21be994
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 132 deletions.
119 changes: 9 additions & 110 deletions .github/actions/build-package/action.yml
Original file line number Diff line number Diff line change
@@ -1,125 +1,24 @@
name: "Build dependency package locally"
description: "Checks out a dependency package locally and updates all references to it"
name: 'Build dependency package locally'
description: 'Checks out a dependency package locally and updates all references to it'
inputs:
package:
description: "Name of the package"
description: 'Name of the package'
required: true
download_dependencies:
description: "Whether to download dependencies"
default: "false"
skip_build:
description: "Whether to skip the build"
default: "false"
skip_tests:
description: "Whether to skip the tests"
default: "false"
target_artifact:
description: "Name of the artifact that will be uploaded"
default: "dependencies"
artifact_path:
description: "Path or pattern for the artifact files that should be uploaded"

runs:
using: "composite"
using: 'composite'
steps:
- name: Clone
uses: actions/checkout@v3
with:
repository: cloudscape-design/${{ inputs.package }}
path: ${{ inputs.package }}
- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16

- name: Download artifacts
if: ${{ inputs.download_dependencies == 'true' }}
uses: actions/download-artifact@v2
with:
name: dependencies

- run: cd ${{ inputs.package }}
shell: bash

- uses: cloudscape-design/.github/.github/actions/patch-local-dependencies@main
with:
path: ${{ github.workspace }}/${{ inputs.package }}
type: local

- name: npm install
shell: bash
run: npm i --force
working-directory: ${{ inputs.package }}
- name: Build
if: ${{ inputs.skip_build != 'true' }}
shell: bash
run: npm run build
working-directory: ${{ inputs.package }}
- name: Test
if: ${{ inputs.skip_tests != 'true' }}
shell: bash
run: npm test
working-directory: ${{ inputs.package }}
- name: Pack artifacts
if: ${{ inputs.package != 'components' && inputs.package != 'test-utils' && inputs.package != 'theming-core' && inputs.package != 'board-components' && inputs.package != 'demos' }}
shell: bash
working-directory: ${{ inputs.package }}
run: |
npm pack
cp *-${{ inputs.package }}-*.tgz $GITHUB_WORKSPACE/${{ inputs.package }}.tgz
- name: Pack test-utils artifacts
if: ${{ inputs.package == 'test-utils' }}
shell: bash
working-directory: ${{ inputs.package }}
run: |
cd packages/core
npm pack
cp *-test-utils-core-*.tgz $GITHUB_WORKSPACE
cd ../converter
npm pack
echo $GITHUB_WORKSPACE
cp *-test-utils-converter-*.tgz $GITHUB_WORKSPACE
cd $GITHUB_WORKSPACE
mv *-test-utils-converter-*.tgz test-utils-converter.tgz
mv *-test-utils-core-*.tgz test-utils-core.tgz
- name: Pack theming-core artifacts
if: ${{ inputs.package == 'theming-core' }}
shell: bash
working-directory: ${{ inputs.package }}
run: |
cd lib/browser
npm pack
cp *-theming-runtime-*.tgz $GITHUB_WORKSPACE
cd ../node
npm pack
echo $GITHUB_WORKSPACE
cp *-theming-build-*.tgz $GITHUB_WORKSPACE
cd $GITHUB_WORKSPACE
mv *-theming-build-*.tgz theming-build.tgz
mv *-theming-runtime-*.tgz theming-runtime.tgz
- name: Package board components files
if: ${{ inputs.package == 'board-components' }}
shell: bash
working-directory: ${{ inputs.package }}
run: |
cd lib/components
npm pack
cp *-${{ inputs.package }}-*.tgz $GITHUB_WORKSPACE/${{ inputs.package }}.tgz
- name: Package component files
if: ${{ inputs.package == 'components' }}
shell: bash
working-directory: ${{ inputs.package }}
run: |
tar -czf ../components-full.tgz .
tar -czf ../components.tgz --directory=lib/components .
tar -czf ../design-tokens.tgz --directory=lib/design-tokens .
uses: ${{ inputs.package }}/.github/workflows/build-lint-test.yml
env:
AWSUI_DRY_RUN: 'true'
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ inputs.target_artifact }}
path: ${{ inputs.artifact_path || format('{0}*.tgz', inputs.package) }}
name: ${{ inputs.package }}
path: '*.tgz'
35 changes: 25 additions & 10 deletions .github/actions/release-package/index.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import path from 'path';
import { execSync } from 'child_process';
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
import { copyFileSync, existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';

const inputs = {
path: process.env.INPUT_PATH,
suffix: process.env.INPUT_SUFFIX,
isDryRun: process.env.AWSUI_DRY_RUN,
publishPackages: process.env.PUBLISH_PACKAGES
? process.env.PUBLISH_PACKAGES.split(',').map((pkg) => pkg.trim())
: null,
commitSha: process.env.COMMIT_SHA,
commitSha: process.env.COMMIT_SHA,
};

console.log('Inputs:');
console.log(JSON.stringify(inputs, null, 2));

const internalFolderName = 'internal'
const internalFolderName = 'internal';

// The main branch should publish to next, and dev forks to next-dev
const branchName = process.env.GITHUB_REF_TYPE === 'branch' ? process.env.GITHUB_REF_NAME : '';
Expand All @@ -28,24 +29,38 @@ function releasePackage(packagePath) {
packageJson.version += inputs.suffix;

// Add internal folder to files in package.json
if(packageJson.files) {
packageJson.files.push(internalFolderName)
if (packageJson.files) {
packageJson.files.push(internalFolderName);
}

writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));

// Publish to CodeArtifact
console.info(`Publishing package ${packageJson.name} version ${packageJson.version} to dist-tag ${publishTag}`);

if (inputs.isDryRun) {
packDryRunArtifact(packagePath);
} else {
publishPackage(packagePath);
}
}

function packDryRunArtifact(packagePath) {
const output = execSync('npm pack --quiet', { cwd: packagePath }).toString();
const artifactFile = output.split('\n')[0].trim();
const targetFile = output.replace(/^cloudscape-design-/, '').replace(/-\d+.\d+.\d+\./, '.');

console.log(`Copying ${artifactFile} to ${targetFile}`);
copyFileSync(path.join(packagePath, artifactFile), path.join(inputs.path, targetFile));
}

function publishPackage(packagePath) {
execSync(`npm publish --tag ${publishTag}`, { stdio: 'inherit', cwd: packagePath });
}

function addManifest(data, packagePath) {
mkdirSync(path.join(packagePath, internalFolderName), { recursive: true })
writeFileSync(
path.join(packagePath, internalFolderName, 'manifest.json'),
JSON.stringify(data, null, 2)
);
mkdirSync(path.join(packagePath, internalFolderName), { recursive: true });
writeFileSync(path.join(packagePath, internalFolderName, 'manifest.json'), JSON.stringify(data, null, 2));
}

function main() {
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/dry-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,54 @@ jobs:
name: Build jest-preset
runs-on: ubuntu-latest
steps:
- uses: cloudscape-design/.github/.github/actions/build-package@main
- uses: ./.github/actions/build-package/action.yml
with:
package: jest-preset
skip_build: "true"
skip_build: 'true'
buildGlobalStyles:
name: Build global-styles
runs-on: ubuntu-latest
steps:
- uses: cloudscape-design/.github/.github/actions/build-package@main
- uses: ./.github/actions/build-package/action.yml
with:
package: global-styles
buildCollectionHooks:
name: Build collection-hooks
runs-on: ubuntu-latest
steps:
- uses: cloudscape-design/.github/.github/actions/build-package@main
- uses: ./.github/actions/build-package/action.yml
with:
package: collection-hooks
buildBrowserTestTools:
name: Build browser-test-tools
runs-on: ubuntu-latest
steps:
- uses: cloudscape-design/.github/.github/actions/build-package@main
- uses: ./.github/actions/build-package/action.yml
with:
package: browser-test-tools
buildDocumenter:
name: Build documenter
runs-on: ubuntu-latest
steps:
- uses: cloudscape-design/.github/.github/actions/build-package@main
- uses: ./.github/actions/build-package/action.yml
with:
package: documenter
buildTestUtils:
name: Build test-utils
runs-on: ubuntu-latest
needs: buildDocumenter
steps:
- uses: cloudscape-design/.github/.github/actions/build-package@main
- uses: ./.github/actions/build-package/action.yml
with:
package: test-utils
download_dependencies: "true"
download_dependencies: 'true'
buildThemingCore:
name: Build theming-core
runs-on: ubuntu-latest
needs:
- buildBrowserTestTools
steps:
- uses: cloudscape-design/.github/.github/actions/build-package@main
- uses: ./.github/actions/build-package/action.yml
with:
package: theming-core
artifact_path: theming-*.tgz
Expand All @@ -78,7 +78,7 @@ jobs:
needs:
- buildBrowserTestTools
steps:
- uses: cloudscape-design/.github/.github/actions/build-package@main
- uses: ./.github/actions/build-package/action.yml
with:
package: component-toolkit
download_dependencies: true
Expand All @@ -95,7 +95,7 @@ jobs:
- buildThemingCore
- buildComponentToolkit
steps:
- uses: cloudscape-design/.github/.github/actions/build-package@main
- uses: ./.github/actions/build-package/action.yml
with:
package: components
target_artifact: components-package
Expand Down Expand Up @@ -197,7 +197,7 @@ jobs:
with:
name: components-package
- name: Build
uses: cloudscape-design/.github/.github/actions/build-package@main
uses: ./.github/actions/build-package/action.yml
with:
package: demos
download_dependencies: true

0 comments on commit 21be994

Please sign in to comment.