From 242e75b0dad661b4226ddd6a69b23d5e2faeeeea Mon Sep 17 00:00:00 2001 From: Arthus <531151995@qq.com> Date: Fri, 22 Apr 2022 09:59:11 +0800 Subject: [PATCH] feat(deploy_folder): make deploy_folder configable now deploy_folder and angular_dist_build_folder could be different feat(deploy_folder): read me feat(readme): update --- .github/workflows/test.yml | 1 + README.md | 2 ++ __tests__/main.test.ts | 8 ++++++-- action.yml | 5 ++++- dist/index.js | 9 ++++++--- src/commands.ts | 4 +++- src/main.ts | 4 +++- 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 95ea174..a12b218 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,5 +36,6 @@ jobs: build_configuration: # The branch the action should deploy from. base_href: /angular-deploy-gh-pages-actions/ deploy_branch: gh-pages # The branch the action should deploy to. + deploy_folder: ./ angular_dist_build_folder: jokester/dist/jokester # The folder the action should deploy. angular_project_dir: jokester diff --git a/README.md b/README.md index c94c145..0a0feda 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ jobs: build_configuration: staging # The build environment for the app. please look configurations in your angular.json base_href: /my-project/ # make sure this corresponds to https://.github.io// deploy_branch: gh-pages # The branch the action should deploy to. + deploy_folder: ./ # The deploy fold angular_dist_build_folder: dist/my-project # The folder where your project is supposed to be after running ng build by the action. ``` @@ -48,6 +49,7 @@ You have to configure the `with` portion of your workflow file so that the actio | `build_configuration` | You can provide the configuration using which the action should create the build. If nothing is provided, it will run `ng build --prod` by default. See your angular.json file for configurations. | `with` | **Yes** | "production" | | `base_href` | Since gh-pages will deploy the app for https://yourgithubusername.github.io/repositoryname/, you need to provide this `base-href` in order to have your project working correctly, since the base-href won't be `'/'` in this case. Note to use with `@angular/cli@^10.0.0` (Angular version 10), you need the specify the base-href in the angular.json file and then use an empty string as parameter `base_href: '' # empty string to support optional base-href` to make the parameter optional. | `with` | **No** | "/" | | `deploy_branch` | The branch to which we'll deploy the build folder. | `with` | **No** | "gh-pages" | +| `deploy_folder` | The folder to which we'll deploy the build folder. | `with` | **No** | "./" | | `angular_dist_build_folder` | The folder in which `ng build` provides its output for your project. The folder where your index.html resides in. Also, this is the folder which will be deployed to the `deploy_branch`. | `with` | **No** | "dist" | | `run_lint` | Runs the `ng lint` command behind the scenes to make sure the files are linted properly. | `with` | **No** | "false" | | `github_access_token` | Depending on the repository permissions you may need to provide the action with a GitHub personal access token instead of the provided GitHub token in order to deploy. You can [learn more about how to generate one here](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line). **This should be stored as a secret**. | `secrets / with` | **Yes** | diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 256d163..509ba13 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -25,12 +25,14 @@ test('test throws error for deployment if accessToken is not provided', async () const accessToken = '' const buildFolder = './dist/my-app' const deployBranch = 'my-custom-branch' + const deployFolder = './target' process.env['execute_success'] = 'true' await expect( deployBuild({ accessToken, buildFolder, - deployBranch + deployBranch, + deployFolder }) ).rejects.toThrow( 'Github Access token not provided. Please add it to your workflow yml' @@ -41,11 +43,13 @@ test('test runs fine for deployment if all inputs are correct', async () => { const accessToken = 'some-token' const buildFolder = './dist/my-app' const deployBranch = 'my-custom-branch' + const deployFolder = './target' process.env['execute_success'] = 'true' const result = await deployBuild({ accessToken, buildFolder, - deployBranch + deployBranch, + deployFolder }) expect(result).toBe('successfully deployed') }) diff --git a/action.yml b/action.yml index ed90325..99daba8 100644 --- a/action.yml +++ b/action.yml @@ -21,8 +21,11 @@ inputs: deploy_branch: description: "branch on which the angular build will be deployed" default: "gh-pages" + deploy_folder: + description: "This is the folder which will be deployed to the `deploy_branch`." + default: "./" angular_dist_build_folder: - description: "The folder in which `ng build` provides its output. This is the folder which will be deployed to the `deploy_branch`." + description: "The folder in which `ng build` provides its output." default: "dist" run_lint: description: "If the action should run 'ng lint'" diff --git a/dist/index.js b/dist/index.js index a601c64..1e94982 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3818,6 +3818,7 @@ function run() { const shouldRunLint = core_1.getInput('run_lint'); const accessToken = core_1.getInput('github_access_token'); const buildFolder = core_1.getInput('angular_dist_build_folder'); + const deployFolder = core_1.getInput('deploy_folder'); const angularProjectDir = core_1.getInput('angular_project_dir'); const deployBranch = core_1.getInput('deploy_branch'); // if the angular project directory is not the current directory @@ -3844,7 +3845,8 @@ function run() { yield commands.deployBuild({ accessToken, buildFolder, - deployBranch + deployBranch, + deployFolder }); } catch (error) { @@ -3893,7 +3895,7 @@ exports.getUserAgent = getUserAgent; /***/ 215: /***/ (function(module) { -module.exports = {"_args":[["@octokit/rest@16.43.1","/Users/ahsanayaz/Contributions/angular-deploy-gh-pages-actions"]],"_from":"@octokit/rest@16.43.1","_id":"@octokit/rest@16.43.1","_inBundle":false,"_integrity":"sha512-gfFKwRT/wFxq5qlNjnW2dh+qh74XgTQ2B179UX5K1HYCluioWj8Ndbgqw2PVqa1NnVJkGHp2ovMpVn/DImlmkw==","_location":"/@octokit/rest","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"@octokit/rest@16.43.1","name":"@octokit/rest","escapedName":"@octokit%2frest","scope":"@octokit","rawSpec":"16.43.1","saveSpec":null,"fetchSpec":"16.43.1"},"_requiredBy":["/@actions/github"],"_resolved":"https://registry.npmjs.org/@octokit/rest/-/rest-16.43.1.tgz","_spec":"16.43.1","_where":"/Users/ahsanayaz/Contributions/angular-deploy-gh-pages-actions","author":{"name":"Gregor Martynus","url":"https://github.com/gr2m"},"bugs":{"url":"https://github.com/octokit/rest.js/issues"},"bundlesize":[{"path":"./dist/octokit-rest.min.js.gz","maxSize":"33 kB"}],"contributors":[{"name":"Mike de Boer","email":"info@mikedeboer.nl"},{"name":"Fabian Jakobs","email":"fabian@c9.io"},{"name":"Joe Gallo","email":"joe@brassafrax.com"},{"name":"Gregor Martynus","url":"https://github.com/gr2m"}],"dependencies":{"@octokit/auth-token":"^2.4.0","@octokit/plugin-paginate-rest":"^1.1.1","@octokit/plugin-request-log":"^1.0.0","@octokit/plugin-rest-endpoint-methods":"2.4.0","@octokit/request":"^5.2.0","@octokit/request-error":"^1.0.2","atob-lite":"^2.0.0","before-after-hook":"^2.0.0","btoa-lite":"^1.0.0","deprecation":"^2.0.0","lodash.get":"^4.4.2","lodash.set":"^4.3.2","lodash.uniq":"^4.5.0","octokit-pagination-methods":"^1.1.0","once":"^1.4.0","universal-user-agent":"^4.0.0"},"description":"GitHub REST API client for Node.js","devDependencies":{"@gimenete/type-writer":"^0.1.3","@octokit/auth":"^1.1.1","@octokit/fixtures-server":"^5.0.6","@octokit/graphql":"^4.2.0","@types/node":"^13.1.0","bundlesize":"^0.18.0","chai":"^4.1.2","compression-webpack-plugin":"^3.1.0","cypress":"^3.0.0","glob":"^7.1.2","http-proxy-agent":"^4.0.0","lodash.camelcase":"^4.3.0","lodash.merge":"^4.6.1","lodash.upperfirst":"^4.3.1","lolex":"^5.1.2","mkdirp":"^1.0.0","mocha":"^7.0.1","mustache":"^4.0.0","nock":"^11.3.3","npm-run-all":"^4.1.2","nyc":"^15.0.0","prettier":"^1.14.2","proxy":"^1.0.0","semantic-release":"^17.0.0","sinon":"^8.0.0","sinon-chai":"^3.0.0","sort-keys":"^4.0.0","string-to-arraybuffer":"^1.0.0","string-to-jsdoc-comment":"^1.0.0","typescript":"^3.3.1","webpack":"^4.0.0","webpack-bundle-analyzer":"^3.0.0","webpack-cli":"^3.0.0"},"files":["index.js","index.d.ts","lib","plugins"],"homepage":"https://github.com/octokit/rest.js#readme","keywords":["octokit","github","rest","api-client"],"license":"MIT","name":"@octokit/rest","nyc":{"ignore":["test"]},"publishConfig":{"access":"public"},"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"repository":{"type":"git","url":"git+https://github.com/octokit/rest.js.git"},"scripts":{"build":"npm-run-all build:*","build:browser":"npm-run-all build:browser:*","build:browser:development":"webpack --mode development --entry . --output-library=Octokit --output=./dist/octokit-rest.js --profile --json > dist/bundle-stats.json","build:browser:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=Octokit --output-path=./dist --output-filename=octokit-rest.min.js --devtool source-map","build:ts":"npm run -s update-endpoints:typescript","coverage":"nyc report --reporter=html && open coverage/index.html","generate-bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","lint":"prettier --check '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","lint:fix":"prettier --write '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","postvalidate:ts":"tsc --noEmit --target es6 test/typescript-validate.ts","prebuild:browser":"mkdirp dist/","pretest":"npm run -s lint","prevalidate:ts":"npm run -s build:ts","start-fixtures-server":"octokit-fixtures-server","test":"nyc mocha test/mocha-node-setup.js \"test/*/**/*-test.js\"","test:browser":"cypress run --browser chrome","update-endpoints":"npm-run-all update-endpoints:*","update-endpoints:fetch-json":"node scripts/update-endpoints/fetch-json","update-endpoints:typescript":"node scripts/update-endpoints/typescript","validate:ts":"tsc --target es6 --noImplicitAny index.d.ts"},"types":"index.d.ts","version":"16.43.1"}; +module.exports = {"name":"@octokit/rest","version":"16.43.1","publishConfig":{"access":"public"},"description":"GitHub REST API client for Node.js","keywords":["octokit","github","rest","api-client"],"author":"Gregor Martynus (https://github.com/gr2m)","contributors":[{"name":"Mike de Boer","email":"info@mikedeboer.nl"},{"name":"Fabian Jakobs","email":"fabian@c9.io"},{"name":"Joe Gallo","email":"joe@brassafrax.com"},{"name":"Gregor Martynus","url":"https://github.com/gr2m"}],"repository":"https://github.com/octokit/rest.js","dependencies":{"@octokit/auth-token":"^2.4.0","@octokit/plugin-paginate-rest":"^1.1.1","@octokit/plugin-request-log":"^1.0.0","@octokit/plugin-rest-endpoint-methods":"2.4.0","@octokit/request":"^5.2.0","@octokit/request-error":"^1.0.2","atob-lite":"^2.0.0","before-after-hook":"^2.0.0","btoa-lite":"^1.0.0","deprecation":"^2.0.0","lodash.get":"^4.4.2","lodash.set":"^4.3.2","lodash.uniq":"^4.5.0","octokit-pagination-methods":"^1.1.0","once":"^1.4.0","universal-user-agent":"^4.0.0"},"devDependencies":{"@gimenete/type-writer":"^0.1.3","@octokit/auth":"^1.1.1","@octokit/fixtures-server":"^5.0.6","@octokit/graphql":"^4.2.0","@types/node":"^13.1.0","bundlesize":"^0.18.0","chai":"^4.1.2","compression-webpack-plugin":"^3.1.0","cypress":"^3.0.0","glob":"^7.1.2","http-proxy-agent":"^4.0.0","lodash.camelcase":"^4.3.0","lodash.merge":"^4.6.1","lodash.upperfirst":"^4.3.1","lolex":"^5.1.2","mkdirp":"^1.0.0","mocha":"^7.0.1","mustache":"^4.0.0","nock":"^11.3.3","npm-run-all":"^4.1.2","nyc":"^15.0.0","prettier":"^1.14.2","proxy":"^1.0.0","semantic-release":"^17.0.0","sinon":"^8.0.0","sinon-chai":"^3.0.0","sort-keys":"^4.0.0","string-to-arraybuffer":"^1.0.0","string-to-jsdoc-comment":"^1.0.0","typescript":"^3.3.1","webpack":"^4.0.0","webpack-bundle-analyzer":"^3.0.0","webpack-cli":"^3.0.0"},"types":"index.d.ts","scripts":{"coverage":"nyc report --reporter=html && open coverage/index.html","lint":"prettier --check '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","lint:fix":"prettier --write '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","pretest":"npm run -s lint","test":"nyc mocha test/mocha-node-setup.js \"test/*/**/*-test.js\"","test:browser":"cypress run --browser chrome","build":"npm-run-all build:*","build:ts":"npm run -s update-endpoints:typescript","prebuild:browser":"mkdirp dist/","build:browser":"npm-run-all build:browser:*","build:browser:development":"webpack --mode development --entry . --output-library=Octokit --output=./dist/octokit-rest.js --profile --json > dist/bundle-stats.json","build:browser:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=Octokit --output-path=./dist --output-filename=octokit-rest.min.js --devtool source-map","generate-bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","update-endpoints":"npm-run-all update-endpoints:*","update-endpoints:fetch-json":"node scripts/update-endpoints/fetch-json","update-endpoints:typescript":"node scripts/update-endpoints/typescript","prevalidate:ts":"npm run -s build:ts","validate:ts":"tsc --target es6 --noImplicitAny index.d.ts","postvalidate:ts":"tsc --noEmit --target es6 test/typescript-validate.ts","start-fixtures-server":"octokit-fixtures-server"},"license":"MIT","files":["index.js","index.d.ts","lib","plugins"],"nyc":{"ignore":["test"]},"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"bundlesize":[{"path":"./dist/octokit-rest.min.js.gz","maxSize":"33 kB"}]}; /***/ }), @@ -8766,7 +8768,7 @@ function createBuild(params) { exports.createBuild = createBuild; function deployBuild(deployConfig) { return __awaiter(this, void 0, void 0, function* () { - const { accessToken, buildFolder, deployBranch } = deployConfig; + const { accessToken, buildFolder, deployBranch, deployFolder } = deployConfig; if (!accessToken) { throw Error('Github Access token not provided. Please add it to your workflow yml'); } @@ -8779,6 +8781,7 @@ function deployBuild(deployConfig) { accessToken, branch: deployBranch ? deployBranch : 'gh-pages', folder: buildFolder ? buildFolder : './dist', + targetFolder: deployFolder ? deployFolder : './', workspace: './' }); helpers_1.writeToConsole('Deployed build successfully! 🎉🎉🎉'); diff --git a/src/commands.ts b/src/commands.ts index 48d6954..0825a12 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -38,8 +38,9 @@ export async function deployBuild(deployConfig: { accessToken: string buildFolder: string deployBranch: string + deployFolder: string }): Promise { - const {accessToken, buildFolder, deployBranch} = deployConfig + const {accessToken, buildFolder, deployBranch, deployFolder} = deployConfig if (!accessToken) { throw Error( 'Github Access token not provided. Please add it to your workflow yml' @@ -56,6 +57,7 @@ export async function deployBuild(deployConfig: { accessToken, branch: deployBranch ? deployBranch : 'gh-pages', folder: buildFolder ? buildFolder : './dist', + targetFolder: deployFolder ? deployFolder : './', workspace: './' }) writeToConsole('Deployed build successfully! 🎉🎉🎉') diff --git a/src/main.ts b/src/main.ts index 27398aa..327ebd0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,6 +11,7 @@ async function run(): Promise { const shouldRunLint = getInput('run_lint') const accessToken = getInput('github_access_token') const buildFolder = getInput('angular_dist_build_folder') + const deployFolder = getInput('deploy_folder') const angularProjectDir = getInput('angular_project_dir') const deployBranch = getInput('deploy_branch') @@ -42,7 +43,8 @@ async function run(): Promise { await commands.deployBuild({ accessToken, buildFolder, - deployBranch + deployBranch, + deployFolder }) } catch (error) { const skipFailure = getInput('skip_failure')