Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Generate single package-lock.json artifact #523

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/pull-request-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ name: Pull Request Check
on: [pull_request]

jobs:
check-artifacts-lock-yaml:
check-artifacts:
runs-on: ubuntu-22.04
steps:
- name: Checkout che-code source code
uses: actions/checkout@v4
- name: Generate artifacts.lock.yaml
- name: Generate artifacts
run: ./build/artifacts/generate.sh
- name: Check if artifacts.lock.yaml is up to date
- name: Check if artifacts are up to date
run: |
if [[ $(git diff --name-only | wc -l) != 0 ]]; then
# Print difference
git --no-pager diff

echo "[ERROR] artifacts.lock.yaml is not up to date."
echo "[ERROR] Artifacts is not up to date."
echo "[ERROR] Run './build/artifacts/generate.sh' and include file into the commit."
exit 1
fi
Expand Down
37 changes: 32 additions & 5 deletions build/artifacts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ set -e
SCRIPT_DIR=$(dirname "$0")
ROOT_DIR=$(realpath "$SCRIPT_DIR/../..")
ARTIFACTS_LOCK_YAML="$SCRIPT_DIR/artifacts.lock.yaml"
ALL_PACKAGES_LOCK_JSON="$SCRIPT_DIR/package-lock.json"
ALL_PACKAGES_JSON="$SCRIPT_DIR/package.json"

run () {
makeArtifactsLockYaml () {
rm -f $ARTIFACTS_LOCK_YAML

echo "---" >> "$ARTIFACTS_LOCK_YAML"
Expand All @@ -35,7 +37,7 @@ run () {
if [[ ! $SHA256 == "null" ]]; then
FILENAME="$PLUGIN.$VERSION.vsix"
DOWNLOAD_URL="$REPOSITORY/releases/download/v$VERSION/$FILENAME"
check_existance "$DOWNLOAD_URL"
checkUrlExistence "$DOWNLOAD_URL"

echo " # $PLUGIN" >> "$ARTIFACTS_LOCK_YAML"
echo " - download_url: $DOWNLOAD_URL" >> "$ARTIFACTS_LOCK_YAML"
Expand Down Expand Up @@ -66,7 +68,7 @@ run () {
esac

DOWNLOAD_URL="https://github.com/microsoft/ripgrep-prebuilt/releases/download/${RG_VERSION}/ripgrep-${RG_VERSION}-${RG_ARCH_SUFFIX}.tar.gz"
check_existance "$DOWNLOAD_URL"
checkUrlExistence "$DOWNLOAD_URL"

read -r SHA256 rest <<< "$(curl -sL "$DOWNLOAD_URL" | shasum -a 256)"

Expand All @@ -76,10 +78,30 @@ run () {
echo " checksum: sha256:$SHA256" >> "$ARTIFACTS_LOCK_YAML"
done

echo "[INFO] Done"
echo "[INFO] Completed ${ARTIFACTS_LOCK_YAML}"
}

check_existance() {
# Combine all package-lock.json files into a single file
# based on the package.json in the root directory
makeAllPackageLockJson () {
pushd "$ROOT_DIR" > /dev/null

jq '. | del(.packages."")' package-lock.json > "${ALL_PACKAGES_LOCK_JSON}"
find . -name "package-lock.json" | sort | while read file; do
echo "[INFO] Processing file: $file"

jq '.packages | del(."") | . |= with_entries(.value.origin = .value.resolved)' "$file" > /tmp/package.json
OUTPUT=$(jq '.packages += input' "${ALL_PACKAGES_LOCK_JSON}" /tmp/package.json) && echo -n "${OUTPUT}" > "${ALL_PACKAGES_LOCK_JSON}"
done
echo "[INFO] Completed ${ALL_PACKAGES_LOCK_JSON}"

jq '. | del(.scripts)' package.json > "${ALL_PACKAGES_JSON}"
echo "[INFO] Completed ${ALL_PACKAGES_JSON}"

popd > /dev/null
}

checkUrlExistence() {
if curl -sfILo/dev/null "$1"; then
echo "[INFO] Valid url: $1"
else
Expand All @@ -88,4 +110,9 @@ check_existance() {
fi
}

run() {
makeArtifactsLockYaml
makeAllPackageLockJson
}

run
Loading
Loading