什麼是 Github Actions
GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.
過程
一剛開始我在 Features • GitHub Actions 找到 Beanstalk Deploy · Actions · GitHub Marketplace,測試了一下發現,雖然程式碼有上傳到 AWS Elastic Beanstalk,但是 Node.js 沒有正確地執行 npm run production
。
所以我在 step 前面加上了 Cache · Actions · GitHub Marketplace,先在 GitHub Action 內做好 npm run production
再壓縮成 zip 檔案部署至 AWS Elastic Beanstalk。
我猜測是 AWS Elastic Beanstalk 雖然會自行編譯 Node.js 以及 PHP Composer,不過 Laravel 對 Webpack 又包了一層 Laravel Mix,編譯指令已經和原先有落差。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Laravel | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
jobs: | |
deploy-aws-elastic-beanstalk: | |
needs: laravel-tests | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [14.15.5] | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Cache node modules | |
uses: actions/cache@v1 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
# | |
- name: Node ${{ matrix.node-version }} | |
uses: actions/setup-node@v1 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Installing NPM | |
run: npm install | |
- name: Building application | |
run: npm run production | |
- name: Generate deployment package | |
run: zip -r deploy.zip * -x "**.git**" "**node_modules**" | |
- name: Get timestamp | |
uses: gerred/actions/current-time@master | |
id: current-time | |
- name: Run string replace | |
uses: frabert/replace-string-action@master | |
id: format-time | |
with: | |
pattern: '[:\.]+' | |
string: "${{ steps.current-time.outputs.time }}" | |
replace-with: '-' | |
flags: 'g' | |
- name: Beanstalk Deploy for app | |
uses: einaregilsson/beanstalk-deploy@v16 | |
with: | |
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
application_name: poe-stats | |
environment_name: Poestats-env | |
region: ap-northeast-1 | |
version_label: "my-app-${{ steps.format-time.outputs.replaced }}" | |
deployment_package: deploy.zip |