From 86d684dfe922fead70ba574252f18d24984c42b0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 25 Nov 2023 11:12:30 +0100 Subject: [PATCH 01/12] Add directory option --- action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/action.yml b/action.yml index ede48a8..75822b4 100644 --- a/action.yml +++ b/action.yml @@ -27,6 +27,11 @@ inputs: required: false default: "latest" + directory: + description: 'The project root directory' + required: false + default: "." + env-site-name: description: 'Set the `SITE_NAME` environment variable' required: false From 62052063c087329a400309264ce787d1c533d803 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 25 Nov 2023 11:18:29 +0100 Subject: [PATCH 02/12] Set directory input as working directory for all steps Since there is no way to do this on a job level, see https://github.com/orgs/community/discussions/25742 --- action.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/action.yml b/action.yml index 75822b4..52c0620 100644 --- a/action.yml +++ b/action.yml @@ -51,20 +51,24 @@ runs: using: "composite" steps: - name: Add action path to GitHub PATH + working-directory: ${{ inputs.directory }}" run: echo "${{ github.action_path }}" >> $GITHUB_PATH shell: bash - name: Validate input + working-directory: ${{ inputs.directory }}" id: validate-input run: bash validate-input.sh ${{ inputs.deploy-to }} shell: bash - name: Determine install strategy + working-directory: ${{ inputs.directory }}" id: determine-install-strategy run: bash determine-install-strategy.sh shell: bash - name: Print debug information + working-directory: ${{ inputs.directory }}" if: inputs.debug == 'true' run: | echo "Debug mode: ${{ inputs.debug }}" @@ -74,11 +78,13 @@ runs: shell: bash - name: Validate composer.json and composer.lock + working-directory: ${{ inputs.directory }}" if: steps.determine-install-strategy.outputs.install-strategy == 'composer' run: composer validate --strict shell: bash - name: Cache Composer packages + working-directory: ${{ inputs.directory }}" id: composer-cache if: steps.determine-install-strategy.outputs.install-strategy == 'composer' uses: actions/cache@v3 @@ -89,15 +95,18 @@ runs: ${{ runner.os }}-php- - name: Download latest release + working-directory: ${{ inputs.directory }}" if: steps.determine-install-strategy.outputs.install-strategy == 'archive' run: bash download-latest-release.sh ${{ inputs.framework-version }} shell: bash - name: Install dependencies + working-directory: ${{ inputs.directory }}" run: composer install --prefer-dist --no-progress --no-autoloader && composer dump-autoload --quiet shell: bash - name: Set up environment variables + working-directory: ${{ inputs.directory }}" run: bash setup-environment-variables.sh shell: bash @@ -113,10 +122,12 @@ runs: shell: bash - name: Build the site + working-directory: ${{ inputs.directory }}" run: php hyde build --no-interaction --ansi shell: bash - name: Upload artifact + working-directory: ${{ inputs.directory }}" if: inputs.deploy-to == 'artifact' || inputs.upload-artifact == 'true' uses: actions/upload-artifact@v3 with: @@ -124,16 +135,19 @@ runs: path: _site # TODO: Get this from the config file in case it's customized - name: Setup Pages + working-directory: ${{ inputs.directory }}" if: inputs.deploy-to == 'pages' uses: actions/configure-pages@v3 - name: Upload artifact + working-directory: ${{ inputs.directory }}" if: inputs.deploy-to == 'pages' uses: actions/upload-pages-artifact@v1 with: path: _site # TODO: Get this from the config file in case it's customized - name: Deploy to GitHub Pages + working-directory: ${{ inputs.directory }}" id: pages-deployment if: inputs.deploy-to == 'pages' uses: actions/deploy-pages@v1 From 0786ce42ff36e38acf82a1d611e320cd2f98e0c7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 25 Nov 2023 11:22:22 +0100 Subject: [PATCH 03/12] Revert "Set directory input as working directory for all steps" This reverts commit 62052063c087329a400309264ce787d1c533d803. --- action.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/action.yml b/action.yml index 52c0620..75822b4 100644 --- a/action.yml +++ b/action.yml @@ -51,24 +51,20 @@ runs: using: "composite" steps: - name: Add action path to GitHub PATH - working-directory: ${{ inputs.directory }}" run: echo "${{ github.action_path }}" >> $GITHUB_PATH shell: bash - name: Validate input - working-directory: ${{ inputs.directory }}" id: validate-input run: bash validate-input.sh ${{ inputs.deploy-to }} shell: bash - name: Determine install strategy - working-directory: ${{ inputs.directory }}" id: determine-install-strategy run: bash determine-install-strategy.sh shell: bash - name: Print debug information - working-directory: ${{ inputs.directory }}" if: inputs.debug == 'true' run: | echo "Debug mode: ${{ inputs.debug }}" @@ -78,13 +74,11 @@ runs: shell: bash - name: Validate composer.json and composer.lock - working-directory: ${{ inputs.directory }}" if: steps.determine-install-strategy.outputs.install-strategy == 'composer' run: composer validate --strict shell: bash - name: Cache Composer packages - working-directory: ${{ inputs.directory }}" id: composer-cache if: steps.determine-install-strategy.outputs.install-strategy == 'composer' uses: actions/cache@v3 @@ -95,18 +89,15 @@ runs: ${{ runner.os }}-php- - name: Download latest release - working-directory: ${{ inputs.directory }}" if: steps.determine-install-strategy.outputs.install-strategy == 'archive' run: bash download-latest-release.sh ${{ inputs.framework-version }} shell: bash - name: Install dependencies - working-directory: ${{ inputs.directory }}" run: composer install --prefer-dist --no-progress --no-autoloader && composer dump-autoload --quiet shell: bash - name: Set up environment variables - working-directory: ${{ inputs.directory }}" run: bash setup-environment-variables.sh shell: bash @@ -122,12 +113,10 @@ runs: shell: bash - name: Build the site - working-directory: ${{ inputs.directory }}" run: php hyde build --no-interaction --ansi shell: bash - name: Upload artifact - working-directory: ${{ inputs.directory }}" if: inputs.deploy-to == 'artifact' || inputs.upload-artifact == 'true' uses: actions/upload-artifact@v3 with: @@ -135,19 +124,16 @@ runs: path: _site # TODO: Get this from the config file in case it's customized - name: Setup Pages - working-directory: ${{ inputs.directory }}" if: inputs.deploy-to == 'pages' uses: actions/configure-pages@v3 - name: Upload artifact - working-directory: ${{ inputs.directory }}" if: inputs.deploy-to == 'pages' uses: actions/upload-pages-artifact@v1 with: path: _site # TODO: Get this from the config file in case it's customized - name: Deploy to GitHub Pages - working-directory: ${{ inputs.directory }}" id: pages-deployment if: inputs.deploy-to == 'pages' uses: actions/deploy-pages@v1 From ca6fa5f77412bd78dc2bc00fa6b08b06f6f3959b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 25 Nov 2023 11:25:11 +0100 Subject: [PATCH 04/12] Force replace root directory --- action.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/action.yml b/action.yml index 75822b4..f51520d 100644 --- a/action.yml +++ b/action.yml @@ -59,6 +59,24 @@ runs: run: bash validate-input.sh ${{ inputs.deploy-to }} shell: bash + - name: Configure root directory + id: configure-root-directory + run: | + # If the directory input is not the root directory, we replace the current working directory files with the directory input files. + if [ "${{ inputs.directory }}" != "." ]; then + # Create a temporary directory outside of the current working directory. + mkdir ../tmp + # Copy the directory input files to the temporary directory. + cp -r ${{ inputs.directory }}/* ../tmp + # Remove the current working directory files. + rm -rf * + # Copy the temporary directory files to the current working directory. + cp -r ../tmp/* . + # Remove the temporary directory. + rm -rf ../tmp + fi + shell: bash + - name: Determine install strategy id: determine-install-strategy run: bash determine-install-strategy.sh From 76bd90fb98fc1463ceaaaedbb569500255ea45f2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 25 Nov 2023 11:34:54 +0100 Subject: [PATCH 05/12] Extract script file --- action.yml | 15 +-------------- configure-root-directory.sh | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 configure-root-directory.sh diff --git a/action.yml b/action.yml index f51520d..076792c 100644 --- a/action.yml +++ b/action.yml @@ -61,20 +61,7 @@ runs: - name: Configure root directory id: configure-root-directory - run: | - # If the directory input is not the root directory, we replace the current working directory files with the directory input files. - if [ "${{ inputs.directory }}" != "." ]; then - # Create a temporary directory outside of the current working directory. - mkdir ../tmp - # Copy the directory input files to the temporary directory. - cp -r ${{ inputs.directory }}/* ../tmp - # Remove the current working directory files. - rm -rf * - # Copy the temporary directory files to the current working directory. - cp -r ../tmp/* . - # Remove the temporary directory. - rm -rf ../tmp - fi + run: bash configure-root-directory.sh ${{ inputs.directory }} shell: bash - name: Determine install strategy diff --git a/configure-root-directory.sh b/configure-root-directory.sh new file mode 100644 index 0000000..2bdbf0c --- /dev/null +++ b/configure-root-directory.sh @@ -0,0 +1,18 @@ +# If the directory input is not the root directory, we replace the current working directory files with the directory +# input files. This way is more reliable, as GitHub does not support setting a working directory on a job level. + +# Get directory from CLI input +directory=$1 + +if [ "$directory" != "." ]; then + # Create a temporary directory outside of the current working directory. + mkdir ../tmp + # Copy the directory input files to the temporary directory. + cp -r "$directory"/* ../tmp + # Remove the current working directory files. + rm -rf * + # Copy the temporary directory files to the current working directory. + cp -r ../tmp/* . + # Remove the temporary directory. + rm -rf ../tmp +fi From cb2a94d74f618aac830aedd3764cadb2db1c072c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 25 Nov 2023 11:46:03 +0100 Subject: [PATCH 06/12] Verify that the directory input exists --- configure-root-directory.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/configure-root-directory.sh b/configure-root-directory.sh index 2bdbf0c..1f0c875 100644 --- a/configure-root-directory.sh +++ b/configure-root-directory.sh @@ -5,6 +5,12 @@ directory=$1 if [ "$directory" != "." ]; then + # Verify that the directory input exists. + if [ ! -d "$directory" ]; then + echo "Directory $directory does not exist." + exit 1 + fi + # Create a temporary directory outside of the current working directory. mkdir ../tmp # Copy the directory input files to the temporary directory. From 373cf08c5805a486e316d15eecf58bee4148a196 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 25 Nov 2023 16:20:02 +0100 Subject: [PATCH 07/12] Revert "Verify that the directory input exists" This reverts commit cb2a94d74f618aac830aedd3764cadb2db1c072c. --- configure-root-directory.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/configure-root-directory.sh b/configure-root-directory.sh index 1f0c875..2bdbf0c 100644 --- a/configure-root-directory.sh +++ b/configure-root-directory.sh @@ -5,12 +5,6 @@ directory=$1 if [ "$directory" != "." ]; then - # Verify that the directory input exists. - if [ ! -d "$directory" ]; then - echo "Directory $directory does not exist." - exit 1 - fi - # Create a temporary directory outside of the current working directory. mkdir ../tmp # Copy the directory input files to the temporary directory. From 19dd72b7da7ccdd64751a6acc84a1bcef86356a5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 25 Nov 2023 16:19:58 +0100 Subject: [PATCH 08/12] Use clearer syntax --- configure-root-directory.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure-root-directory.sh b/configure-root-directory.sh index 2bdbf0c..50f4dbf 100644 --- a/configure-root-directory.sh +++ b/configure-root-directory.sh @@ -7,10 +7,10 @@ directory=$1 if [ "$directory" != "." ]; then # Create a temporary directory outside of the current working directory. mkdir ../tmp - # Copy the directory input files to the temporary directory. + # Copy the directory input files recursively to the temporary directory. cp -r "$directory"/* ../tmp # Remove the current working directory files. - rm -rf * + rm -rf ./* # Copy the temporary directory files to the current working directory. cp -r ../tmp/* . # Remove the temporary directory. From 0eaf6e4b7810f88e072daf654cfabc9954676060 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 25 Nov 2023 16:24:16 +0100 Subject: [PATCH 09/12] Normalize script syntaxes --- configure-root-directory.sh | 2 -- download-latest-release.sh | 9 +++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/configure-root-directory.sh b/configure-root-directory.sh index 50f4dbf..db917d8 100644 --- a/configure-root-directory.sh +++ b/configure-root-directory.sh @@ -13,6 +13,4 @@ if [ "$directory" != "." ]; then rm -rf ./* # Copy the temporary directory files to the current working directory. cp -r ../tmp/* . - # Remove the temporary directory. - rm -rf ../tmp fi diff --git a/download-latest-release.sh b/download-latest-release.sh index e967c96..5fbf56c 100644 --- a/download-latest-release.sh +++ b/download-latest-release.sh @@ -4,18 +4,19 @@ # Get version from CLI input version=$1 -# Copy all root files to backup directory -cp -r . ../backup +# Copy all root files to temporary backup directory +cp -r . ../tmp # Download latest version of HydePHP git clone https://github.com/hydephp/hyde.git ../hyde --depth 1 # Copy HydePHP files to root cp -r ../hyde/* . + # Remove default pages rm _pages/index.blade.php _pages/404.blade.php # Copy Backup files to root -cp -r ../backup/* . +cp -r ../tmp/* . # If version is set to something other than latest, require that framework version if [[ "$version" != "latest" ]]; then -composer require hyde/framework:"$version" --no-install + composer require hyde/framework:"$version" --no-install fi From 0b8bcfd9f844da645a0ec33175dd2b187649bf55 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 25 Nov 2023 16:31:48 +0100 Subject: [PATCH 10/12] Cleanup filesystem --- configure-root-directory.sh | 3 +++ download-latest-release.sh | 3 +++ 2 files changed, 6 insertions(+) diff --git a/configure-root-directory.sh b/configure-root-directory.sh index db917d8..814b756 100644 --- a/configure-root-directory.sh +++ b/configure-root-directory.sh @@ -13,4 +13,7 @@ if [ "$directory" != "." ]; then rm -rf ./* # Copy the temporary directory files to the current working directory. cp -r ../tmp/* . + + # Remove the temporary directory. + rm -rf ../tmp fi diff --git a/download-latest-release.sh b/download-latest-release.sh index 5fbf56c..3914ca1 100644 --- a/download-latest-release.sh +++ b/download-latest-release.sh @@ -16,6 +16,9 @@ rm _pages/index.blade.php _pages/404.blade.php # Copy Backup files to root cp -r ../tmp/* . +# Remove the temporary directory. +rm -rf ../tmp + # If version is set to something other than latest, require that framework version if [[ "$version" != "latest" ]]; then composer require hyde/framework:"$version" --no-install From 37758addfc68afcf6929f9876329e05512389ea8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 25 Nov 2023 16:49:11 +0100 Subject: [PATCH 11/12] Update readme to include directory option --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d7da5ba..7278dcc 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ There are a few more configuration options available, that can be supplied to th | `upload-artifact` | Upload the site artifact, regardless of the `deploy-to` option | `false` | | `debug` | Enable additional debug output | `false` | | `framework-version` | Specify the HydePHP Framework version to use
(only applicable for [anonymous projects](https://hydephp.github.io/action/#anonymous-projects)) | "latest" | +| `directory` | The directory to use as the project root | none | | `env-site-name` | Set the `SITE_NAME` environment variable | _none_ | | `env-site-url` | Set the `SITE_URL` environment variable | _none_ | | `env-torchlight-token` | Set the `TORCHLIGHT_TOKEN` environment variable | _none_ | From 3847aff5b009c54bca711c4d5faa17c558b7e555 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 25 Nov 2023 16:49:16 +0100 Subject: [PATCH 12/12] Document directory option --- docs/index.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/index.md b/docs/index.md index 16682ad..65e862f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -181,6 +181,14 @@ This is only used when the anonymous project strategy is used, (i.e. when the pr * **Required**: `false` * **Default**: `"latest"` +### `directory` + +Specifies the directory containing the source files to build. This is useful if your source files are not located in the root directory of the repository. + +* **Description**: Specify the directory containing the source files to build. +* **Required**: `false` +* **Default**: `"."` + ### Environment variables >warning If your inputs contain sensitive information, you should use [GitHub Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets) to store them.