NodeJS 在Azure上将Angular应用部署到静态Web应用

de90aj5v  于 11个月前  发布在  Node.js
关注(0)|答案(1)|浏览(114)

我有一个angular应用程序,我想通过git hub actions部署在azure静态web应用程序上。在我的本地机器上:angular 17 node 20 npm 10
这是yaml文件。

name: Azure Static Web Apps CI/CD

on:
  push:
    branches:
      - master
  pull_request:
    types: [opened, synchronize, reopened, closed]
    branches:
      - master

jobs:
  build_and_deploy_job:
    if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
    runs-on: ubuntu-latest
    name: Build and Deploy Job
    steps:
      - uses: actions/setup-node@v4
        with:
          node-version: '18'
      - uses: actions/checkout@v4
        with:
          sub-modules: true
      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_VICTORIOUS_DESERT_030B8CE03 }}
          repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
          action: "upload"
          ###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
          # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
          app_location: "/" # App source code path
          api_location: "api" # Api source code path - optional
          output_location: "dist/sun-club" # Built app content directory - optional
          ###### End of Repository/Build Configurations ######

  close_pull_request_job:
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    runs-on: ubuntu-latest
    name: Close Pull Request Job
    steps:
      - name: Close Pull Request
        id: closepullrequest
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_VICTORIOUS_DESERT_030B8CE03 }}
          action: "close"

字符串
我犯了这个错误。
检测到Node.js版本v16.20.2。Angular CLI要求最低Node.js版本v18.13。
我尝试用yaml文件中的命令更新节点版本,但似乎节点16是默认的。
我尝试使用nvm更新节点版本,但没有成功。

vxf3dgd4

vxf3dgd41#

你可以在更新的版本中使用Github actions/setup-node action。

name: Azure Static Web Apps CI/CD

on:
  push:
    branches:
      - master
  pull_request:
    types: [opened, synchronize, reopened, closed]
    branches:
      - master

jobs:
  build_and_deploy_job:
    if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
    runs-on: ubuntu-latest
    name: Build and Deploy Job
    steps:
      - name: Setup Node.js
        uses: actions/setup-node@v3  # Use v3 instead of v4
        with:
          node-version: '18'
      - uses: actions/checkout@v2
        with:
          sub-modules: true
      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_VICTORIOUS_DESERT_030B8CE03 }}
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          action: "upload"
          app_location: "/"
          api_location: "api"
          output_location: "dist/sun-club"

  close_pull_request_job:
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    runs-on: ubuntu-latest
    name: Close Pull Request Job
    steps:
      - name: Close Pull Request
        id: closepullrequest
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_VICTORIOUS_DESERT_030B8CE03 }}
          action: "close"

字符串
我将actions/setup-node@v4更改为actions/setup-node@v3,以使用支持Node.js 18的旧版本的action。
如果成功了就告诉我

相关问题