diff --git a/.github/actions/build-package/action.yml b/.github/actions/build-package/action.yml index e357617..ca4a7fd 100644 --- a/.github/actions/build-package/action.yml +++ b/.github/actions/build-package/action.yml @@ -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' diff --git a/.github/actions/release-package/index.mjs b/.github/actions/release-package/index.mjs index 55fc075..a47573f 100644 --- a/.github/actions/release-package/index.mjs +++ b/.github/actions/release-package/index.mjs @@ -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 : ''; @@ -28,8 +29,8 @@ 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)); @@ -37,15 +38,29 @@ function releasePackage(packagePath) { // 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() { diff --git a/.github/workflows/dry-run.yml b/.github/workflows/dry-run.yml index ad20b7e..bede522 100644 --- a/.github/workflows/dry-run.yml +++ b/.github/workflows/dry-run.yml @@ -20,36 +20,36 @@ 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: @@ -57,17 +57,17 @@ jobs: 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 @@ -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 @@ -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 @@ -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