Sure, here's an HTML version of the technical blog post about moving files and folders up one level within the distribution directory, formatted as per your requirements:
Moving Files and Folders Up One Level Within the Distribution Directory
Introduction
Rearranging files manually after the build process is unreliable in a CI/CD context. It adds inconsistency and potential errors. Automating the file restructuring within the build process itself ensures consistency and repeatability, which are crucial for any automated deployment process.
Solution1. Add the following post-build script in your project's package.json
to handle the file movement:
"scripts": { "build": "ng build --configuration=production", "postbuild": "mv dist/maindirectory/* dist/ && rm -rf dist/maindirectory", "test": "..." }
2. Remove the --if-present
flags. The build step would be:
- name: npm install, build, and test run: | npm install npm run build npm test working-directory: MyApp/Client
3. Run npm run build
to automatically trigger the postbuild
script, ensuring the desired file structure.
4. Update your workflow to include the file movement logic within the project:
GitHub Repo |__ (Push to develop branch) |__ GitHub Actions Pipeline (Updated YAML) |__ Build Job (Windows) | |__ Checkout | |__ Setup Node.js | |__ npm install, build (with postbuild), test | |__ Upload artifact | |__ Deploy Job (Ubuntu) |__ Download artifact |__ Login to Azure |__ Deploy to Azure Web AppCross-Platform Solution
If you encounter the error "mv is not recognized" in a Windows environment, you can use a cross-platform solution:
1. Install shx
: npm install shx --save-dev
2. Update the postbuild
script:
"scripts": { "build": "ng build --configuration=production", "postbuild": "shx mv dist/maindirectory/* dist/ && shx rm -rf dist/maindirectory && shx rm -rf dist/secondarydirectory/web.config", "test": "..." }
3. Ensure that dependencies are installed in your GitHub Actions workflow:
jobs: build: runs-on: windows-latest steps: - uses: actions/checkout@v4 - name: Set up Node.js version uses: actions/setup-node@v3 with: node-version: '18.x' - name: Install npm dependencies run: npm install - name: npm install, build, and test run: | npm run build npm run test working-directory: MyApp/Client # rest of the workflow
Conclusion
Automating the file restructuring within the build process ensures consistency and repeatability, making it a more reliable solution for CI/CD pipelines.
Additional Information