-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh: streamline publishable packages and updated branchign
- Loading branch information
1 parent
a25f1ae
commit dafa3c5
Showing
6 changed files
with
100 additions
and
175 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
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
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,73 @@ | ||
# A publishable package is a package that has been modified and, if the | ||
# if the branch is production, has a new version. | ||
|
||
name: Get packages that should be published | ||
on: | ||
workflow_call: | ||
inputs: | ||
package-names: | ||
description: 'Package names to consider, separated by commas.' | ||
required: true | ||
type: string | ||
outputs: | ||
publishable-packages: | ||
description: 'Returns the name of all packages that should be published.' | ||
value: ${{ jobs.publishable-packages.outputs.publishable-packages }} | ||
|
||
jobs: | ||
publishable-packages: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
publishable-packages: ${{ steps.publishable-packages.outputs.sanitized_packages }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b | ||
|
||
- name: Get modified dirs | ||
id: modified-dirs | ||
uses: tj-actions/changed-files@a29e8b565651ce417abb5db7164b4a2ad8b6155c | ||
with: | ||
since_last_remote_commit: true | ||
dir_names: true | ||
dir_names_max_depth: 2 | ||
separator: ',' | ||
files: ${{ github.event.inputs.paths }} | ||
|
||
- name: Get publishable packages | ||
id: publishable-packages | ||
run: | | ||
# Extract changed directories from output, removing the 'package/' prefix | ||
# Example: packages/hop-node,packages/v2-explorer-backend,packages/frontend | ||
modified_dirs="${{ steps.modified-dirs.outputs.all_changed_files }}" | ||
# Read input package names, compare with modified directories | ||
# Example: packages/hop-node,packages/v2-explorer-backend | ||
IFS=":" | ||
read -a input_packages <<< "${{ inputs.package-names }}" | ||
modified_packages="" | ||
|
||
for package in "${input_packages[@]}"; do | ||
package_path="packages/$package" | ||
|
||
# Skip packages not modified | ||
if [[ $modified_dirs != *"$package_path"* ]]; then | ||
continue | ||
fi | ||
|
||
# On the production branch, publish only if there's a version change | ||
if [ "${{ github.head_ref }}" == "production" ]; then | ||
version_changed=$(git diff HEAD^ HEAD -- "${package_path}/package.json" | grep '"version":' || true) | ||
if [ "$version_changed" ]; then | ||
continue | ||
fi | ||
fi | ||
|
||
modified_packages+="$package," | ||
done | ||
|
||
# Format the string of modified packages as an array for matrix consumption | ||
# Example: ["hop-node", "v2-explorer-backend"] | ||
modified_packages="${modified_packages%,}" | ||
modified_packages=$(echo $modified_packages | tr ',' '\n' | sed 's/^ *//;s/ *$//' | jq -R -s -c 'split("\n")[:-1]') | ||
|
||
echo "modified_packages=$modified_packages" >> $GITHUB_OUTPUT |
Oops, something went wrong.