首页 > 解决方案 > 使用特定节点版本与 Azure 一起部署静态 Web 应用程序

问题描述

我正在尝试使用带有 Github Actions 的 Azure 服务部署静态 Web 应用程序。

问题是,我需要使用 NodeJS 运行脚本。我正在使用在 Node v14 中运行良好的 ESM 模块。问题是,在构建任务期间,Azure(或 github)使用不支持 ESM 模块的 v12.8(我猜是 LTS)。

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/checkout@v2
        with:
          submodules: true

      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v0.0.1-preview
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_LEMON_GLACIER_0C510BD03 }}
          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 you 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
          app_artifact_location: "public" # 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@v0.0.1-preview
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_LEMON_GLACIER_0C510BD03 }}
          action: "close"

我试图使用此步骤指定节点版本:

- name: Setup Node 14.x
  uses: actions/setup-node@v1
    with:
      node-version: '14.x'

尽管如此,构建过程仍然使用 12.8。

我做错了什么,是否可以在我的情况下使用特定版本?

标签: node.jsazuregithub-actions

解决方案


文档说支持的 Node 版本仅与 LTS 一样高。目前12.8。您现在不能对 v14.x 使用 Azure/static-web-apps-deploy@v0.0.1-preview 操作。

我通过使用 github-actions 并将构建推送到 azure 存储解决了这个问题。


推荐阅读