From 72576765a6fe4590e5123cd8ffa9c9df6a3b65f5 Mon Sep 17 00:00:00 2001 From: Yuriy Stovbur Date: Sun, 24 Jan 2021 13:16:04 +0600 Subject: [PATCH] install recipes only for deployer 6 and earlier --- README.md | 2 +- action.yml | 3 +++ src/SetupDeployer.ts | 20 ++++++++++++++++++++ src/index.ts | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 25ab482..e7067a2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This action makes it easy to deploy your php services using [Github Actions](htt * Starts the `ssh-agent` * Loads your deployment SSH private key into the agent * Configures `known_hosts` with your provided key (or turns of SSH host key checking) -* Installs deployer +* Installs deployer & deployer recipes ## Using the action diff --git a/action.yml b/action.yml index df58054..96b47e4 100755 --- a/action.yml +++ b/action.yml @@ -13,6 +13,9 @@ inputs: deployer-version: description: 'Version of deployer to install' required: false + deployer-recipes-version: + description: 'Version of deployer recipes to install' + required: false deployer-skip-install: description: 'Skip install of deployer (if you are using a locally installed version)' required: false diff --git a/src/SetupDeployer.ts b/src/SetupDeployer.ts index 062ec34..bcd91e7 100644 --- a/src/SetupDeployer.ts +++ b/src/SetupDeployer.ts @@ -3,9 +3,19 @@ const core = require('@actions/core'); interface DeployerOptions { deployerVersion?: string, + deployerRecipesVersion?: string, skipDeployerInstall?: string, } +const getInstalledDeployerMajorVersion = async (): Promise => { + const {stdout} = await execa('composer', ['global', 'show', 'deployer/deployer']); + + const regexp = /^versions.*?(\d+)/im; + const matches = regexp.exec(stdout); + + return matches && +matches[1]; +} + export default async (options: DeployerOptions): Promise => { if (options.skipDeployerInstall) return; @@ -15,6 +25,16 @@ export default async (options: DeployerOptions): Promise => { await execa('composer', ['global', 'require', deployerPackage]); + const deployerMajor = await getInstalledDeployerMajorVersion(); + + if (deployerMajor && deployerMajor <= 6) { + const deployerRecipesPackage = options.deployerRecipesVersion + ? `deployer/recipes:${options.deployerRecipesVersion}` + : 'deployer/recipes'; + + await execa('composer', ['global', 'require', deployerRecipesPackage]); + } + const installPath = (await execa('composer', ['global', 'config', 'home'])).stdout; core.addPath(`${installPath}/vendor/bin`); }; diff --git a/src/index.ts b/src/index.ts index 7426460..a02f49b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ const tasks = new taskz([ text: 'Install Deployer', task: () => SetupDeployer({ deployerVersion: core.getInput('deployer-version'), + deployerRecipesVersion: core.getInput('deployer-recipes-version'), skipDeployerInstall: core.getInput('deployer-skip-install'), }) },