name: AiDA WEB-Node.js StableVersion 分支构建部署 on: schedule: # cron为UTC时区,构建时间=部署时间-8小时 {*分 (-8)时 *日 *月 *周} --- # 示例: 1月1日22点22分触发构建 cron写作 - '22 14 1 1 *' - cron: '59 15 28 11 *' jobs: build: runs-on: ubuntu-latest strategy: matrix: node-version: [ 18.18.0 ] steps: - name: 1.检出代码 uses: actions/checkout@v4 with: ref: StableVersion - name: 2.打印当前分支信息 run: | echo "Current branch being deployed is: $(git rev-parse --abbrev-ref HEAD)" echo "The code is from the 'main' branch, as specified in 'actions/checkout'." - name: 3.设置 Node.js 环境 ${{ matrix.node-version }} uses: actions/setup-node@v6 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm run build - run: ls -l - name: 3.5. 手动安装 AWS CLI v2 # 新增步骤:确保 aws 命令可用 run: | echo "安装 AWS CLI V2..." curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip sudo ./aws/install --update aws --version echo "AWS CLI V2 安装完成。" - name: 4.配置 AWS 凭证 uses: aws-actions/configure-aws-credentials@main with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: 'ap-east-1' - name: 5.同步 dist 目录到 S3 run: | aws s3 sync dist/* s3://${{ secrets.S3_BUCKET_NAME }}/ --acl public-read - name: 6.部署完成 run: echo "构建和部署到 S3 任务完成。"