Skip to content

Commit

Permalink
WIP on re-wrapping text files. ref: #40
Browse files Browse the repository at this point in the history
  • Loading branch information
joemaller committed Aug 18, 2023
1 parent b4fd997 commit 64b368a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/__snapshots__/prefix/bump-phpunit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# This script is a part of the ideasonpurpose/docker-phpunit-watch project
# https://github.com/ideasonpurpose/docker-phpunit-watch
#
# Version: 1.6.18
#
# For now, manually update the PHPUnit version in phpunit-version.json before running
#
# This script does a few things:
# - Updates the PHPUnit version in Dockerfile
# - Updates the PHPUnit version in README.md
#
# The phpunit-version.json file should be commited to Git. The push-to-dockerhub
# GitHub Action uses this file to generate tag names for the Docker Image.

# style helpers
RESET="\033[0m"
BOLD="\033[1m"
RED="\033[31m"
GREEN="\033[32m"
GOLD="\033[33m"
BLUE="\033[34m"
MAGENTA="\033[35m"
CYAN="\033[36m"

PHPUNIT_LATEST=$(jq -r '.phpunit' /app/phpunit-version.json)

echo -e "✏️ Updating ${GOLD}Dockerfile${RESET} to ${CYAN}phpunit-${PHPUNIT_LATEST}.phar${RESET}"
sed -i "s/phpunit.de\/phpunit-.*phar/phpunit.de\/phpunit-${PHPUNIT_LATEST}.phar/" /app/Dockerfile

echo -e "✏️ Updating ${GOLD}README.md${RESET} to ${CYAN}v${PHPUNIT_LATEST}${RESET}"
sed -E -i "s/^<\!-- PHPUNIT_VERSION -->- PHPUnit.+$/<\!-- PHPUNIT_VERSION -->- PHPUnit ${PHPUNIT_LATEST}/" /app/README.md
17 changes: 17 additions & 0 deletions test/snapshots.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("Snapshot Tests:", () => {
const newVersion = "1.414.213";

testFiles.forEach((file) => {
// console.log(file);
test(path.basename(file), () => {
const src = fs.readFileSync(file).toString();

Expand All @@ -39,3 +40,19 @@ describe("Snapshot Tests:", () => {
});
});
});

describe("Shell script re-wrapping with prefix", () => {
const newVersion = "1.6.18";

/**
* This is testing a problem discovered with https://github.com/ideasonpurpose/docker-phpunit-watch
* where the bump-phpunit.sh script was being re-wrapped when the version was updated.
*/
test("re-wrapped shell script", async () => {
const result = await updateFile("./test/snapshots/prefix/bump-phpunit.sh", newVersion, {dryRun: true, prefixes: ['hello']});
console.log(result);
expect(result?.data).toMatchFileSnapshot(
"./__snapshots__/prefix/bump-phpunit.sh"
);
});
});
33 changes: 33 additions & 0 deletions test/snapshots/prefix/bump-phpunit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# This script is a part of the ideasonpurpose/docker-phpunit-watch project
# https://github.com/ideasonpurpose/docker-phpunit-watch
#
# Version: 0.9.4
#
# For now, manually update the PHPUnit version in phpunit-version.json before running
#
# This script does a few things:
# - Updates the PHPUnit version in Dockerfile
# - Updates the PHPUnit version in README.md
#
# The phpunit-version.json file should be commited to Git. The push-to-dockerhub
# GitHub Action uses this file to generate tag names for the Docker Image.

# style helpers
RESET="\033[0m"
BOLD="\033[1m"
RED="\033[31m"
GREEN="\033[32m"
GOLD="\033[33m"
BLUE="\033[34m"
MAGENTA="\033[35m"
CYAN="\033[36m"

PHPUNIT_LATEST=$(jq -r '.phpunit' /app/phpunit-version.json)

echo -e "✏️ Updating ${GOLD}Dockerfile${RESET} to ${CYAN}phpunit-${PHPUNIT_LATEST}.phar${RESET}"
sed -i "s/phpunit.de\/phpunit-.*phar/phpunit.de\/phpunit-${PHPUNIT_LATEST}.phar/" /app/Dockerfile

echo -e "✏️ Updating ${GOLD}README.md${RESET} to ${CYAN}v${PHPUNIT_LATEST}${RESET}"
sed -E -i "s/^<\!-- PHPUNIT_VERSION -->- PHPUnit.+$/<\!-- PHPUNIT_VERSION -->- PHPUnit ${PHPUNIT_LATEST}/" /app/README.md

0 comments on commit 64b368a

Please sign in to comment.