-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Create new build-repository action
- Use shared build-repository action - Update upload/download artifacts to v4 - Simplify unlock-dependencies custom action
- Loading branch information
1 parent
b29f076
commit 92ef351
Showing
14 changed files
with
290 additions
and
384 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
name: Build repository | ||
description: Builds a repository | ||
inputs: | ||
repository: | ||
description: Name of the repository | ||
required: true | ||
skip-lint: | ||
required: false | ||
type: boolean | ||
default: true | ||
skip-tests: | ||
required: false | ||
type: boolean | ||
default: false | ||
cache-working-directory: | ||
required: false | ||
type: boolean | ||
default: false | ||
artifact-path: | ||
type: string | ||
description: An optional file, directory or wildcard pattern that describes what to upload | ||
default: '' | ||
artifact-name: | ||
type: string | ||
description: An optional artifact name. Required when artifact-path is specified | ||
default: '' | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: ${{ inputs.repository }} | ||
- name: Set-up node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Download dependencies artifacts | ||
id: download-artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
pattern: cloudscape-design-* | ||
path: ./.build-cache | ||
merge-multiple: true | ||
|
||
- name: Patch local dependencies | ||
uses: cloudscape-design/actions/.github/actions/patch-local-dependencies@test/use-build-repository | ||
` with: | ||
path: ${{ github.workspace }} | ||
|
||
- name: Unlock dependencies | ||
uses: cloudscape-design/actions/.github/actions/unlock-dependencies@test/use-build-repository | ||
- name: Install | ||
shell: bash | ||
run: npm install | ||
- name: Build | ||
shell: bash | ||
run: npm run build | ||
- name: Lint | ||
if: ${{ inputs.skip-lint != 'true' }} | ||
shell: bash | ||
run: npm run lint | ||
- name: Test | ||
if: ${{ inputs.skip-tests != 'true' && inputs.repository != 'cloudscape-design/components' }} | ||
shell: bash | ||
run: npm run test | ||
- name: Test:Unit | ||
if: ${{ inputs.skip-tests != 'true' && inputs.repository == 'cloudscape-design/components' }} | ||
shell: bash | ||
run: npm run test:unit | ||
|
||
- name: Cache working directory folder | ||
if: ${{ inputs.cache-working-directory == 'true' }} | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ github.workspace }} | ||
key: ${{ inputs.repository }}-${{ github.event.pull_request.head.sha || github.sha }} | ||
|
||
- name: Package lib | ||
shell: bash | ||
run: | | ||
cd ./lib | ||
if [ -f "package.json" ]; then | ||
# If there's a package.json in ./lib, just pack it here | ||
echo "Found package.json in ./lib, running npm pack in ./lib" | ||
npm pack | ||
else | ||
# Otherwise, iterate through subdirectories and pack if package.json exists | ||
echo "No package.json found in ./lib, iterating through subdirectories" | ||
for dir in */; do | ||
if [ -f "$dir/package.json" ]; then | ||
cd "$dir" | ||
npm pack | ||
mv *.tgz ../ | ||
cd .. | ||
else | ||
echo "No package.json in $dir, skipping npm pack" | ||
fi | ||
done | ||
fi | ||
- name: Sanitize package name | ||
shell: bash | ||
id: sanitize | ||
run: | | ||
SANITIZED_NAME=$(echo "${{ inputs.repository }}" | sed 's/@//g' | sed 's/\//-/g') | ||
echo "sanitized_name=$SANITIZED_NAME" >> $GITHUB_OUTPUT | ||
echo "SANITIZED_NAME=$SANITIZED_NAME" | ||
- name: Upload build artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ steps.sanitize.outputs.sanitized_name }} | ||
path: lib/*.tgz | ||
|
||
- name: Upload additional artifacts | ||
if: ${{ inputs.artifact-path != '' && inputs.artifact-name != '' }} | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ inputs.artifact-name }} | ||
path: ${{ inputs.artifact-path }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Adapted from https://github.com/actions/toolkit/blob/main/packages/core/src/core.ts#L126C1-L138C2 | ||
function getInput(name, options) { | ||
const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || '' | ||
if (options && options.required && !val) { | ||
throw new Error(`Input required and not supplied: ${name}`) | ||
} | ||
|
||
if (options && options.trimWhitespace === false) { | ||
return val | ||
} | ||
|
||
return val.trim() | ||
} | ||
|
||
module.exports = { getInput }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const core = require('./core'); | ||
|
||
const rootPath = core.getInput('path'); | ||
const tarballDir = core.getInput('tarball-dir'); | ||
|
||
const packageJsonFullPath = path.resolve(path.join(rootPath, 'package.json')); | ||
const tarballDirFullPath = path.resolve(tarballDir); | ||
|
||
if (!fs.existsSync(tarballDirFullPath)) { | ||
console.log('No local tarball directory found. No local dependencies will be loaded.'); | ||
return; | ||
} | ||
|
||
if (!fs.existsSync(packageJsonFullPath)) { | ||
throw new Error(`package.json not found at path: ${packageJsonFullPath}`); | ||
} | ||
|
||
const packageJsonData = JSON.parse(fs.readFileSync(packageJsonFullPath, 'utf8')); | ||
const tarballFiles = fs.readdirSync(tarballDirFullPath).filter(file => file.endsWith('.tgz')); | ||
|
||
const updateCloudscapeDependencies = dependencies => { | ||
if (!dependencies) return {}; | ||
return Object.keys(dependencies).reduce((updatedDeps, key) => { | ||
if (key.startsWith('@cloudscape-design/')) { | ||
const tarball = tarballFiles.find(file => file.replace('cloudscape-design-', '').startsWith(key.replace('@cloudscape-design/', ''))); | ||
if (tarball) { | ||
console.log(`Updating ${key} to tarball file: ${tarball}`); | ||
updatedDeps[key] = `file:${path.join(tarballDirFullPath, tarball)}`; | ||
} else { | ||
console.log(`No tarball found for ${key}, skipping update.`); | ||
updatedDeps[key] = dependencies[key]; | ||
} | ||
} else { | ||
updatedDeps[key] = dependencies[key]; | ||
} | ||
return updatedDeps; | ||
}, {}); | ||
}; | ||
|
||
packageJsonData.dependencies = updateCloudscapeDependencies(packageJsonData.dependencies); | ||
packageJsonData.devDependencies = updateCloudscapeDependencies(packageJsonData.devDependencies); | ||
|
||
fs.writeFileSync(packageJsonFullPath, JSON.stringify(packageJsonData, null, 2)); | ||
|
||
console.log(`Successfully updated @cloudscape-design/* dependencies to point to local tarballs.`); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.