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

Snapshot integration node engine #1041

Open
wants to merge 18 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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
runs-on: ${{ matrix.arch == 'arm64' && 'pub-hk-ubuntu-24.04-arm-medium' || 'ubuntu-24.04' }}
env:
INTEGRATION_TEST_CNB_BUILDER: heroku/builder:${{ matrix.builder_tag }}
INTEGRATION_TEST_CNB_ARCH: ${{ matrix.arch }}
needs: find-libcnb-buildpacks
strategy:
fail-fast: false
Expand Down
161 changes: 161 additions & 0 deletions .github/workflows/update_snapshots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
name: Update Snapshots

on:
workflow_dispatch:

jobs:
find-libcnb-buildpacks:
name: Find libcnb buildpacks
runs-on: ubuntu-24.04

outputs:
libcnb-buildpacks: ${{ steps.find-buildpack-dirs.outputs.buildpacks }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- id: find-buildpack-dirs
name: Find libcnb buildpack directories
run: |
echo "buildpacks=$( \
find . -type d -execdir test -e "{}/buildpack.toml" -a -e "{}/Cargo.toml" \; -print \
| sort \
| uniq \
| jq -nRc '[inputs]
| map({ dir: ., name: split("/") | last | split("nodejs-") | last }
| [
. + { builder_tag: 20, arch: "amd64" },
. + { builder_tag: 22, arch: "amd64" },
. + { builder_tag: 24, arch: "amd64" },
. + { builder_tag: 24, arch: "arm64" }
])
| flatten' \
)" >> $GITHUB_OUTPUT

update-snapshots:
name: Snapshot ${{ matrix.name }} (${{ matrix.builder_tag }}, ${{ matrix.arch }})
runs-on: ${{ matrix.arch == 'arm64' && 'pub-hk-ubuntu-24.04-arm-medium' || 'ubuntu-24.04' }}

env:
INTEGRATION_TEST_CNB_BUILDER: heroku/builder:${{ matrix.builder_tag }}
INTEGRATION_TEST_CNB_ARCH: ${{ matrix.arch }}

needs: find-libcnb-buildpacks

strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.find-libcnb-buildpacks.outputs.libcnb-buildpacks) }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install musl-tools
run: sudo apt-get install musl-tools -y --no-install-recommends

- name: Update Rust toolchain
run: rustup update

- name: Install Rust linux-musl target
run: rustup target add ${{ matrix.arch == 'arm64' && 'aarch64-unknown-linux-musl' || 'x86_64-unknown-linux-musl' }}

- name: Rust Cache
uses: Swatinem/[email protected]

- name: Install cargo-insta
run: cargo install cargo-insta

- name: Install cargo-get
run: cargo install cargo-get

- name: Install Pack CLI
uses: buildpacks/github-actions/[email protected]

- name: Pull builder image
run: docker pull ${{ env.INTEGRATION_TEST_CNB_BUILDER }}

- name: Pull run image
run: |
RUN_IMAGE=$(
docker inspect --format='{{index .Config.Labels "io.buildpacks.builder.metadata"}}' '${{ env.INTEGRATION_TEST_CNB_BUILDER }}' \
| jq --exit-status --raw-output '.stack.runImage.image'
)
docker pull "${RUN_IMAGE}"

- name: Get package name
id: get-package-name
working-directory: ${{ matrix.dir }}
run: echo "package=$(cargo get package.name)" >> $GITHUB_OUTPUT

- name: Rebuild integration test snapshots
env:
# This seems to be required because CI=true changes the behavior of how `cargo insta` treats various flags
# and setting CI=false allows the tests to run without fail in GHA to update the necessary snapshots.
CI: false
run: |
cargo insta test \
--accept \
--force-update-snapshots \
--test integration_test \
--package ${{ steps.get-package-name.outputs.package }} \
-- --ignored --test-threads 16

- name: Create Snapshot Patch
run: |
git add .
git diff --cached > ${{ matrix.name }}_${{ matrix.builder_tag }}_${{ matrix.arch }}.patch

- name: Upload Snapshot Patch
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}_${{ matrix.builder_tag }}_${{ matrix.arch }}
path: ${{ matrix.name }}_${{ matrix.builder_tag }}_${{ matrix.arch }}.patch
if-no-files-found: error
retention-days: 1

create-pr:
name: Create Snapshots PR
needs: [update-snapshots]
runs-on: pub-hk-ubuntu-24.04-ip
steps:
- uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ vars.LINGUIST_GH_APP_ID }}
private-key: ${{ secrets.LINGUIST_GH_PRIVATE_KEY }}

- name: Checkout
uses: actions/checkout@v4

- name: Download Snapshot Patches
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: ${{ runner.temp }}/patches

- name: Apply Snapshot Patches
run: |
git apply --allow-empty "${{ runner.temp }}/patches"/*.patch
git add -A

- name: Create Pull Request
id: pr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ steps.generate-token.outputs.token }}
title: "Update Snapshots"
commit-message: "Update Node.js CNB snapshots"
committer: ${{ vars.LINGUIST_GH_APP_USERNAME }} <${{ vars.LINGUIST_GH_APP_EMAIL }}>
author: ${{ vars.LINGUIST_GH_APP_USERNAME }} <${{ vars.LINGUIST_GH_APP_EMAIL }}>
branch: update-snapshots
body: "Automated pull-request to update Node.js CNB snapshots"

- name: Configure PR
if: steps.pr.outputs.pull-request-operation == 'created'
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
run: gh pr merge --squash --auto "${{ steps.pr.outputs.pull-request-number }}"
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 8 additions & 24 deletions buildpacks/nodejs-engine/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
// Required due to: https://github.com/rust-lang/rust/issues/95513
#![allow(unused_crate_dependencies)]

use libcnb_test::assert_contains;
use test_support::{
assert_web_response, nodejs_integration_test, nodejs_integration_test_with_config,
set_node_engine,
assert_web_response, create_build_snapshot, nodejs_integration_test,
nodejs_integration_test_with_config, set_node_engine,
};

#[test]
#[ignore]
fn simple_indexjs() {
nodejs_integration_test("./fixtures/node-with-indexjs", |ctx| {
assert_contains!(
ctx.pack_stderr,
"Node.js version not specified, using `22.x`"
);
assert_contains!(ctx.pack_stderr, "Installing Node.js");
create_build_snapshot(&ctx.pack_stderr).assert();
assert_web_response(&ctx, "node-with-indexjs");
});
}
Expand All @@ -24,20 +19,7 @@ fn simple_indexjs() {
#[ignore]
fn simple_serverjs() {
nodejs_integration_test("./fixtures/node-with-serverjs", |ctx| {
assert_contains!(ctx.pack_stderr, "Detected Node.js version range: `16.0.0`");
if cfg!(target_arch = "aarch64") {
assert_contains!(
ctx.pack_stderr,
"Downloading Node.js `16.0.0 (linux-arm64)` from https://nodejs.org/download/release/v16.0.0/node-v16.0.0-linux-arm64.tar.gz"
);
assert_contains!(ctx.pack_stderr, "Installing Node.js `16.0.0 (linux-arm64)`");
} else {
assert_contains!(
ctx.pack_stderr,
"Downloading Node.js `16.0.0 (linux-amd64)` from https://nodejs.org/download/release/v16.0.0/node-v16.0.0-linux-x64.tar.gz"
);
assert_contains!(ctx.pack_stderr, "Installing Node.js `16.0.0 (linux-amd64)`");
}
create_build_snapshot(&ctx.pack_stderr).assert();
assert_web_response(&ctx, "node-with-serverjs");
});
}
Expand All @@ -53,13 +35,15 @@ fn reinstalls_node_if_version_changes() {
});
},
|ctx| {
assert_contains!(ctx.pack_stderr, "Installing Node.js `14");
let build_snapshot = create_build_snapshot(&ctx.pack_stderr);

let mut config = ctx.config.clone();
config.app_dir_preprocessor(|app_dir| {
set_node_engine(&app_dir, "^16.0");
});

ctx.rebuild(config, |ctx| {
assert_contains!(ctx.pack_stderr, "Installing Node.js `16");
build_snapshot.rebuild_output(&ctx.pack_stderr).assert();
});
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
source: test_support/src/lib.rs
---
# Heroku Node.js Engine

- Checking Node.js version
- Detected Node.js version range: `>=14.0.0 <15.0.0-0`
- Resolved Node.js version: `14.21.3`
- Installing Node.js distribution
- Downloading Node.js `14.21.3 (linux-amd64)` from https://nodejs.org/download/release/v14.21.3/node-v14.21.3-linux-x64.tar.gz ... (<time_elapsed>)
- Verifying checksum
- Extracting Node.js `14.21.3 (linux-amd64)`
- Installing Node.js `14.21.3 (linux-amd64)` ... (<time_elapsed>)
- Done (finished in <time_elapsed>)

--------------------------------------------- REBUILD ---------------------------------------------

# Heroku Node.js Engine

- Checking Node.js version
- Detected Node.js version range: `>=16.0.0 <17.0.0-0`
- Resolved Node.js version: `16.20.2`
- Installing Node.js distribution
- Downloading Node.js `16.20.2 (linux-amd64)` from https://nodejs.org/download/release/v16.20.2/node-v16.20.2-linux-x64.tar.gz ... (<time_elapsed>)
- Verifying checksum
- Extracting Node.js `16.20.2 (linux-amd64)`
- Installing Node.js `16.20.2 (linux-amd64)` ... (<time_elapsed>)
- Done (finished in <time_elapsed>)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
source: test_support/src/lib.rs
---
# Heroku Node.js Engine

- Checking Node.js version
- Detected Node.js version range: `>=14.0.0 <15.0.0-0`
- Resolved Node.js version: `14.21.3`
- Installing Node.js distribution
- Downloading Node.js `14.21.3 (linux-amd64)` from https://nodejs.org/download/release/v14.21.3/node-v14.21.3-linux-x64.tar.gz ... (<time_elapsed>)
- Verifying checksum
- Extracting Node.js `14.21.3 (linux-amd64)`
- Installing Node.js `14.21.3 (linux-amd64)` ... (<time_elapsed>)
- Done (finished in <time_elapsed>)

--------------------------------------------- REBUILD ---------------------------------------------

# Heroku Node.js Engine

- Checking Node.js version
- Detected Node.js version range: `>=16.0.0 <17.0.0-0`
- Resolved Node.js version: `16.20.2`
- Installing Node.js distribution
- Downloading Node.js `16.20.2 (linux-amd64)` from https://nodejs.org/download/release/v16.20.2/node-v16.20.2-linux-x64.tar.gz ... (<time_elapsed>)
- Verifying checksum
- Extracting Node.js `16.20.2 (linux-amd64)`
- Installing Node.js `16.20.2 (linux-amd64)` ... (<time_elapsed>)
- Done (finished in <time_elapsed>)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
source: test_support/src/lib.rs
---
# Heroku Node.js Engine

- Checking Node.js version
- Detected Node.js version range: `>=14.0.0 <15.0.0-0`
- Resolved Node.js version: `14.21.3`
- Installing Node.js distribution
- Downloading Node.js `14.21.3 (linux-amd64)` from https://nodejs.org/download/release/v14.21.3/node-v14.21.3-linux-x64.tar.gz ... (<time_elapsed>)
- Verifying checksum
- Extracting Node.js `14.21.3 (linux-amd64)`
- Installing Node.js `14.21.3 (linux-amd64)` ... (<time_elapsed>)
- Done (finished in <time_elapsed>)

--------------------------------------------- REBUILD ---------------------------------------------

# Heroku Node.js Engine

- Checking Node.js version
- Detected Node.js version range: `>=16.0.0 <17.0.0-0`
- Resolved Node.js version: `16.20.2`
- Installing Node.js distribution
- Downloading Node.js `16.20.2 (linux-amd64)` from https://nodejs.org/download/release/v16.20.2/node-v16.20.2-linux-x64.tar.gz ... (<time_elapsed>)
- Verifying checksum
- Extracting Node.js `16.20.2 (linux-amd64)`
- Installing Node.js `16.20.2 (linux-amd64)` ... (<time_elapsed>)
- Done (finished in <time_elapsed>)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
source: test_support/src/lib.rs
assertion_line: 313
---
# Heroku Node.js Engine

- Checking Node.js version
- Detected Node.js version range: `>=14.0.0 <15.0.0-0`
- Resolved Node.js version: `14.21.3`
- Installing Node.js distribution
- Downloading Node.js `14.21.3 (linux-arm64)` from https://nodejs.org/download/release/v14.21.3/node-v14.21.3-linux-arm64.tar.gz ... (<time_elapsed>)
- Verifying checksum
- Extracting Node.js `14.21.3 (linux-arm64)`
- Installing Node.js `14.21.3 (linux-arm64)` ... (<time_elapsed>)
- Done (finished in <time_elapsed>)

--------------------------------------------- REBUILD ---------------------------------------------

# Heroku Node.js Engine

- Checking Node.js version
- Detected Node.js version range: `>=16.0.0 <17.0.0-0`
- Resolved Node.js version: `16.20.2`
- Installing Node.js distribution
- Downloading Node.js `16.20.2 (linux-arm64)` from https://nodejs.org/download/release/v16.20.2/node-v16.20.2-linux-arm64.tar.gz ... (<time_elapsed>)
- Verifying checksum
- Extracting Node.js `16.20.2 (linux-arm64)`
- Installing Node.js `16.20.2 (linux-arm64)` ... (<time_elapsed>)
- Done (finished in <time_elapsed>)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: test_support/src/lib.rs
---
# Heroku Node.js Engine

- Checking Node.js version
- Node.js version not specified, using `22.x`
- Resolved Node.js version: `22.14.0`
- Installing Node.js distribution
- Downloading Node.js `22.14.0 (linux-amd64)` from https://nodejs.org/download/release/v22.14.0/node-v22.14.0-linux-x64.tar.gz ... (<time_elapsed>)
- Verifying checksum
- Extracting Node.js `22.14.0 (linux-amd64)`
- Installing Node.js `22.14.0 (linux-amd64)` ... (<time_elapsed>)
- Done (finished in <time_elapsed>)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: test_support/src/lib.rs
---
# Heroku Node.js Engine

- Checking Node.js version
- Node.js version not specified, using `22.x`
- Resolved Node.js version: `22.14.0`
- Installing Node.js distribution
- Downloading Node.js `22.14.0 (linux-amd64)` from https://nodejs.org/download/release/v22.14.0/node-v22.14.0-linux-x64.tar.gz ... (<time_elapsed>)
- Verifying checksum
- Extracting Node.js `22.14.0 (linux-amd64)`
- Installing Node.js `22.14.0 (linux-amd64)` ... (<time_elapsed>)
- Done (finished in <time_elapsed>)
Loading