Upload 'ng build' to S3 Bucket - amazon-s3

I am trying to upload my angular-meteor project's 'ng build' to S3 Bucket.
This is my .yml file
on:
push:
branches:
- dev
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Setup meteor
uses: meteorengineer/setup-meteor#v1
with:
meteor-release: '1.8.1'
- name: Install Node.js
uses: actions/setup-node#v1
with:
node-version: '10.x'
- name: NG build Angular
run: ng build --prod
- name: Deploy to S3
uses: jakejarvis/s3-sync-action#master
with:
args: --acl public-read --delete
env:
AWS_S3_BUCKET: ${{ secrets.DEV_AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SOURCE_DIR: 'browser'
Once I run this, I am receiving this error message for the NG build Angular section
Instead of running ng build --prod i have also tried to run ng build — prod — aot, ng build -- --prod & npm run build -- --prod but Still I am receiving the same error message.
Does anyone know how to solve this problem?

By default GitHub runners won't have ng/angular cli. So we got to install it . Below piece of code should do the job for you.
on:
push:
branches:
- dev
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Setup meteor
uses: meteorengineer/setup-meteor#v1
with:
meteor-release: '1.8.1'
- name: Install Node.js
uses: actions/setup-node#v1
with:
node-version: '10.x'
- name: Install Angular CLI
run: npm install -g #angular/cli
- name: NG build Angular
run: ng build --prod
- name: Deploy to S3
uses: jakejarvis/s3-sync-action#master
with:
args: --acl public-read --delete

#angular/cli is installed as a devDependency, so you have to use:
- name: NG build Angular
run: npx ng build --prod
or in Angular 12+
- name: NG build Angular
run: npx ng build --configuration production

Related

Deploy expo app to GitHub Pages using Action

I am trying to build an Action on GitHub to have always up-to-date the web version of my app. However, it is not updating.
For the first deploy, I followed the expo deploy to GitHub Pages documentation. Then, I built the following workflow:
name: Web
on:
push:
branches:
- main
workflow_dispatch:
jobs:
web:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: ⚙️ Set up repository
uses: actions/checkout#v2
- name: ❇️ Setup Node.js environment
uses: actions/setup-node#v3.6.0
with:
node-version: 16.x
- name: 🔷 Set up Expo
uses: expo/expo-github-action#v7
with:
expo-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- name: 📦 Install dependencies
run: yarn install
- name: ⤴️ Export the app
run: |
git remote set-url origin https://git:${GITHUB_TOKEN}#github.com/${GITHUB_REPOSITORY}.git
yarn deploy -- -u "github-actions-bot <support+actions#github.com>"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 🚀 Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages#v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./
I also changed the Pages settings to deploy from an Action.
However, when the action ran it did not update the website. I decided to change back to the branch deployment, but now my site is crashing.
Have anyone ever done it? I could not find any reference browsing on the internet.

lerna publish push to npm, but not updating dependencies

My Monorepo is currently managed by Lerna.js.
It all works fine except for the GitHub actions workflow I use to automate the npm publishing.
The situation is as follows:
I update packages/types-lib, then update packages/server with new types.
Upon completion, I push everything to GitHub, and the action is bumping packages/types-lib version.
However, it does not update the packages/types-lib listed in packages/server as a dependency.
Locally, it works, but not in the workflow...
Here is my workflow code:
name: Publish To NPM
on:
push:
branches:
- main
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout#v2
with:
fetch-depth: 0
- name: "Use NodeJS 16.14.2"
uses: actions/setup-node#v2
with:
node-version: '16.14.2'
- name: "Setup npm"
run: |
npm set #pastelabs:registry=https://registry.npmjs.org/
npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
- name: Install dependencies
run: |
yarn install --frozen-lockfile
yarn lerna bootstrap
- name: Run builds # Run build of all packages
run: yarn lerna run build
- name: Run tests # Run tests of all packages
run: yarn lerna run test
- name: "Version and publish to NPM" # Interesting step
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor}}#users.noreply.github.com"
if [ ${{ github.base_ref }} = develop ]; then
npx --yarn lerna version patch --exact --no-private --conventional-commits --conventional-prerelease --preid beta --yes
else
npx --yarn lerna version patch --exact --no-private --conventional-commits --conventional-graduate --yes
fi
npx --yarn lerna publish from-git --yes --exact

Github action npm publish use tag name

I'm migrating our existing Travis tasks to GH actions. For Travis the command below would publish to npm and use the release tag name for the npm version.
script: yarn npm-bundle && npm version $TRAVIS_BRANCH --allow-same-version -m
"chore - release version %s [skip ci]" --allow-empty
Unfortunately changing to the below doesn't work...
run: |
yarn npm-bundle && npm version ${{ github.event.release.tag_name }} --allow-same-version -m "chore - release version %s [skip ci]" --allow-empty
npm publish --access public --dry-run
Its obviously empty as npm is using the version from package.json. I've tried some other variables such as ${{ github.head_ref }}
also...
run: |
yarn npm-bundle -m "chore - release version %s [skip ci]" --allow-empty
npm publish --tag ${{ github.event.release.tag_name }} --allow-same-version --access public --dry-run
I have resolved the issue by refactoring to the following...
- uses: actions/setup-node#v1
with:
node-version: 14.15.0
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: git config --global user.name "${{ github.actor }}"
- run: git config --global user.email "github-action-${{ github.actor }}#users.noreply.github.com"
- run: npm version ${{ github.event.release.tag_name }}
- run: yarn npm-bundle
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
You can use the npm-publish action in your workflow instead of the script you used in Travis.
If you look for more actions available with NPM, you can find them on thee Github Marketplace
For example here, you could use something like this in your workflow, adapting in with your context with other run step if you need to use yarn or other commands:
on: push
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-node#v1
with:
node-version: 10
- run: npm install
- run: npm test
- uses: JS-DevTools/npm-publish#v1
with:
token: ${{ secrets.NPM_TOKEN }}
tag: <your release tag name>
For more information regarding how this action work, check here.
Other Action
This other action (publish-to-npm) could be interesting as well if you want to check.

GitHub Actions Upload Artifact not finding provided path from npm run build

I'm trying to set up a react website using CICD principles. I can run it locally, use 'npm run build' to get a build folder, and the website works fine when I manually push the files to S3. However, when I try to run the build and deployment through github actions, the upload-artifacts step gives the following warning: 'Warning: No files were found with the provided path: build. No artifacts will be uploaded.' Obviously the deploy job then fails since it can't find any artifacts to download. Why exactly is this happening? The build folder is definitely being created since running ls after the build lists it as one of the folders in the current working directory.
name: frontend_actions
on:
workflow_dispatch:
push:
paths:
- 'frontend/'
- '.github/workflows/frontend_actions.yml'
branches:
- master
defaults:
run:
working-directory: frontend
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
- name: npm install
run: npm install
- name: npm build
run: npm run build
env:
CI: false
- name: Upload Artifact
uses: actions/upload-artifact#master
with:
name: build
path: build
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Download Artifact
uses: actions/download-artifact#master
with:
name: build
path: build
- name: Deploy to S3
uses: jakejarvis/s3-sync-action#master
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-west-2' # optional: defaults to us-east-1
SOURCE_DIR: 'build' # optional: defaults to entire repository
It turns out that my knowledge of github actions was incomplete. When setting a default working directory for jobs, the default directory is only used by commands that use 'run'. Hence all of the 'uses' actions are run in the base directory. I guess I've never encountered this issue since I've never tried uploading/downloading artifacts that weren't created in a base github directory.
Fixed the issue by changing the path from 'build/' to 'frontend/build'.

GitHub Action: Deploy output of vue-cli-service build to Azure App Service

I'm using a GitHub action to deploy to Azure App Service, and, although the npm build succeeds, I cannot figure out how to get the output of that build to be deployed along with the output of the .NET build.
As you can see in my workflow file, for the .NET build, I specified --output ./deploy and then at the bottom, that is deployed via package: './deploy'
However I don't know how to get the npm build output into './deploy'. Currently, the npm build places the output into ClientApp/dist, according to vue.config.js.
Vue config relevant line: outputDir: path.resolve(__dirname, "ClientApp/dist")
Entire action workflow file:
name: CI
on:
push:
branches: [ master ]
jobs:
build-all:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-dotnet#v1
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
with:
dotnet-version: '5.0.x'
- run: dotnet build ./source/trunk/my/project.csproj --output ./deploy
- name: Frontend build
working-directory: ./source/trunk/my/project
run: |
npm install
npm install #vue/cli-service
npx -p #vue/cli vue-cli-service build --mode development
- name: Azure login
uses: azure/login#v1.1
with:
creds: ${{ secrets.MY_SECRET}}
enable-AzPSSession: false
- name: Azure deploy
uses: azure/webapps-deploy#v2
with:
app-name: my-app-name
package: './deploy'