Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
upload

GitHub Action

aliyun-oss-website-action

v1.2.0

aliyun-oss-website-action

upload

aliyun-oss-website-action

Deploy your static website on aliyun OSS

Installation

Copy and paste the following snippet into your .yml file.

              

- name: aliyun-oss-website-action

uses: fangbinwei/aliyun-oss-website-action@v1.2.0

Learn more about this action in fangbinwei/aliyun-oss-website-action

Choose a version

aliyun-oss-website-action

deploy website on aliyun OSS(Alibaba Cloud OSS)

将静态网站部署在阿里云OSS

概览

  • 在阿里云OSS创建一个存放网站的bucket
  • 准备一个域名, 可能需要备案(bucket选择非大陆区域, 可以不备案, 但是如果CDN加速区域包括大陆, 仍然需要备案)
  • 在你的网站repo中, 配置github action, 当action触发, 会清除bucket中原有的文件, 上传网站repo生成的资源文件到bucket中
  • 通过阿里云OSS的CDN, 可以很方便地加速网站的访问, 支持HTTPS

Usage

    - name: upload files to OSS
      uses: fangbinwei/aliyun-oss-website-action@v1
      with:
          accessKeyId: ${{ secrets.ACCESS_KEY_ID }}
          accessKeySecret: ${{ secrets.ACCESS_KEY_SECRET }}
          bucket: your-bucket-name
          # e.g. "oss-cn-shanghai.aliyuncs.com", 也可以填写自定义域名(需要配置cname 为 true)
          endpoint: ali-oss-endpoint
          folder: your-website-output-folder

配置项

  • accessKeyId: 必填
  • accessKeySecret: 必填
  • endpoint: 必填
  • folder: 必填, repo打包输出的资源文件夹
  • bucket: 必填,部署网站的bucket, 用于存放网站的资源
  • cname: 默认false. 若endpoint填写自定义域名, 需设置为true
  • indexPage: 默认index.html.网站首页(用于静态页面配置)
  • notFoundPage: 默认404.html.网站404页面(用于静态页面配置)
  • skipSetting: 默认false, 是否跳过设置静态页面配置
  • htmlCacheControl: 默认no-cache
  • imageCacheControl: 默认max-age=864000
  • otherCacheControl: 默认max-age=2592000
  • exclude: 不上传folder下的某些文件/文件夹

Cache-Control

为上传的资源默认设置的Cache-Control如下

资源类型 Cache-Control
.html no-cache
.png/jpg...(图片资源) max-age=864000(10days)
other max-age=2592000(30days)

静态页面配置

默认的, action会将阿里云OSS的静态页面配置成如下 2020-08-06-03-18-25

若不需要action来设置, 可以配置skipSettingtrue

exclude

如果folder下的某些文件不需要上传

    - name: exclude some files
      uses: fangbinwei/aliyun-oss-website-action@v1
      with:
        folder: dist
        exclude: |
          tmp.txt
          tmp/
          tmp2/*.txt
          tmp2/*/*.txt
      # match dist/tmp.txt
      # match dist/tmp/
      # match dist/tmp2/a.txt
      # match dist/tmp2/a/b.txt not match dist/tmp2/tmp3/b.txt

不支持**

或者

- name: Clean files before upload
  run: rm -f dist/tmp.txt

Demo

部署VuePress项目

name: deploy vuepress

on:
  push:
    branches:
      - master

jobs:
  build:

    runs-on: ubuntu-latest
    steps:
      # load repo to /github/workspace
    - uses: actions/checkout@v2
      with:
          repository: fangbinwei/blog
          fetch-depth: 0
    - name: Use Node.js
      uses: actions/setup-node@v1
      with:
        node-version: '12'
    - run: npm install yarn@1.22.4 -g
    - run: yarn install
    # 打包文档命令
    - run: yarn docs:build
    - name: upload files to OSS
      uses: fangbinwei/aliyun-oss-website-action@v1
      with:
          accessKeyId: ${{ secrets.ACCESS_KEY_ID }}
          accessKeySecret: ${{ secrets.ACCESS_KEY_SECRET }}
          bucket: "your-bucket-name"
          endpoint: "oss-cn-shanghai.aliyuncs.com" 
          folder: ".vuepress/dist"

具体可以参考本项目的workflow, npm/yarn配合action/cache加速依赖安装

Vue

see here

- name: upload files to OSS
      uses: fangbinwei/aliyun-oss-website-action@v1
      with:
          accessKeyId: ${{ secrets.ACCESS_KEY_ID }}
          accessKeySecret: ${{ secrets.ACCESS_KEY_SECRET }}
          bucket: website-spa-vue-demo
          endpoint: oss-spa-demo.fangbinwei.cn
          cname: true
          folder: dist
          notFoundPage: index.html
          htmlCacheControl: no-cache
          imageCacheControl: max-age=864001
          otherCacheControl: max-age=2592001

Hugo

TODO

Hexo

TODO