Eri*_*ell 5 azure node.js github-actions
我正在尝试使用 Azure 服务和 Github Actions 来部署静态 Web 应用程序。
问题是,我需要使用 NodeJS 运行脚本。我正在使用 ESM 模块,这些模块在 Node v14 中运行良好。问题是,在构建任务期间,Azure(或github)使用v12.8(我猜是LTS),其中不支持ESM模块。
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"
Run Code Online (Sandbox Code Playgroud)
我试图使用此步骤指定节点版本:
- name: Setup Node 14.x
uses: actions/setup-node@v1
with:
node-version: '14.x'
Run Code Online (Sandbox Code Playgroud)
尽管如此,构建过程仍然使用 12.8。
我做错了什么,是否可以在我的情况下使用特定版本?
对于像我这样在 12.8(实际上是 14.x)被认为是“遗留”版本之后才提出这个问题的人来说,然而 static-web-apps-deploy,即使在 v1 中,仍然继续使用旧版本的 Node(在我的案例,14.19.1),我在Edi Wang 的博客文章中找到了答案。它表示要向 package.json 添加一个“engine”属性,并使用一个“node”属性指定您需要的版本。由于我想要 v16 或更高版本,所以我添加了以下内容:
"engines": {
"node": ">=16.0.0"
},
Run Code Online (Sandbox Code Playgroud)
这导致 Oryx 查找并下载 Node v17.6.0:
Detecting platforms...
Detected following platforms:
nodejs: 17.6.0
Version '17.6.0' of platform 'nodejs' is not installed. Generating script to install it...
Run Code Online (Sandbox Code Playgroud)
文档称支持的 Node 版本仅高至 LTS。目前12.8。目前无法对 v14.x 使用 Azure/static-web-apps-deploy@v0.0.1-preview 操作。
我通过使用 github-actions 并将构建推送到天蓝色存储解决了这个问题。
| 归档时间: |
|
| 查看次数: |
2073 次 |
| 最近记录: |