{"id":17917732,"url":"https://github.com/fangbinwei/aliyun-oss-website-action","last_synced_at":"2025-07-18T07:03:37.375Z","repository":{"id":38265681,"uuid":"284262750","full_name":"fangbinwei/aliyun-oss-website-action","owner":"fangbinwei","description":"将网站部署到阿里云OSS. Deploy website on aliyun OSS(Alibaba Cloud OSS)","archived":false,"fork":false,"pushed_at":"2024-08-08T02:40:19.000Z","size":1686,"stargazers_count":86,"open_issues_count":10,"forks_count":21,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-06T06:58:54.407Z","etag":null,"topics":["aliyun-oss","github-action","static-website"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fangbinwei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-01T13:12:55.000Z","updated_at":"2025-04-28T08:51:15.000Z","dependencies_parsed_at":"2024-06-20T13:07:53.029Z","dependency_job_id":"efe3d6e5-ef69-42bc-99f9-797986bfb2b5","html_url":"https://github.com/fangbinwei/aliyun-oss-website-action","commit_stats":{"total_commits":61,"total_committers":2,"mean_commits":30.5,"dds":"0.016393442622950838","last_synced_commit":"0aa5c83b38896b9fb13a6bd4330f603f5200af5f"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fangbinwei%2Faliyun-oss-website-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fangbinwei%2Faliyun-oss-website-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fangbinwei%2Faliyun-oss-website-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fangbinwei%2Faliyun-oss-website-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fangbinwei","download_url":"https://codeload.github.com/fangbinwei/aliyun-oss-website-action/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252638598,"owners_count":21780615,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aliyun-oss","github-action","static-website"],"created_at":"2024-10-28T20:08:32.285Z","updated_at":"2025-05-07T12:43:18.654Z","avatar_url":"https://github.com/fangbinwei.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aliyun-oss-website-action\n\ndeploy website on aliyun OSS(Alibaba Cloud OSS)\n\n将静态网站部署在阿里云OSS\n\n## 概览\n- 在阿里云OSS创建一个存放网站的bucket\n- 准备一个域名, 可能需要备案(bucket选择非大陆区域, 可以不备案, 但是如果CDN加速区域包括大陆, 仍然需要备案)\n- 在你的网站repo中, 配置github action, action 触发则**增量上传**网站repo生成的资源文件到bucket中\n- 通过阿里云OSS的CDN, 可以很方便地加速网站的访问, 支持HTTPS\n\u003e 阿里云HTTPS免费证书停止自动续签, 但是可以自己[申请免费的证书](https://help.aliyun.com/document_detail/156645.htm), 具体解决方案参考[该公告](https://help.aliyun.com/document_detail/479351.html)\n\n## Usage\n\n```yml\n    - name: upload files to OSS\n      uses: fangbinwei/aliyun-oss-website-action@v1\n      with:\n          accessKeyId: ${{ secrets.ACCESS_KEY_ID }}\n          accessKeySecret: ${{ secrets.ACCESS_KEY_SECRET }}\n          bucket: your-bucket-name\n          # use your own endpoint\n          endpoint: oss-cn-shanghai.aliyuncs.com\n          folder: your-website-output-folder\n```\n\u003e 如果你使用了environment secret请[查看这里](#配置了environment-secret怎么不生效)\n### 配置项\n- `accessKeyId`: **必填**\n- `accessKeySecret`: **必填**\n- `endpoint`: **必填**, 支持指定protocol, 例如`https://example.org`或者`http://example.org`\n- `folder`: **必填**, repo打包输出的资源文件夹\n- `bucket`: **必填**,部署网站的bucket, 用于存放网站的资源\n- `indexPage`: 默认`index.html`.网站首页(用于[静态页面配置](#静态页面配置))\n- `notFoundPage`: 默认`404.html`.网站404页面(用于[静态页面配置](#静态页面配置))\n- `incremental`: 默认`true`. 使用增量上传.\n- `skipSetting`: 默认`false`, 是否跳过设置[静态页面配置](#静态页面配置)\n- `htmlCacheControl`: 默认`no-cache`\n- `imageCacheControl`: 默认`max-age=864000`\n- `pdfCacheControl`: 默认`max-age=2592000`\n- `otherCacheControl`: 默认`max-age=2592000`\n- `exclude`: 不上传`folder`下的某些文件/文件夹\n- `cname`: 默认`false`. 若`endpoint`填写自定义域名/bucket域名, 需设置为`true`. (使用CDN的场景下, 不推荐使用自定义域名)\n\n## incremental\n**开启`incremental`**\n上传文件到OSS后, 还会将文件的`ContentMD5`和`Cache-Control`收集到名为`.actioninfo`的私有文件中. 当再次触发action的时候, 会将待上传的文件信息与`.actioninfo`中记录的信息比对, 信息未发生变化的文件将跳过上传步骤, 只进行增量上传. 且在上传之后, 根据`.actioninfo`和已上传的文件信息, 将OSS中多余的文件进行删除.\n\n\u003e `.actioninfo` 记录了上一次action执行时, 所上传的文件信息. 私有, 不可公共读写.\n\n**关闭`incremental`** 或 OSS中不存在`.actioninfo`文件\n\n会执行如下步骤\n1. 清除所有OSS中已有的文件\n2. 上传新的文件到OSS中\n\n\u003e **计划未来优化这个步骤, 优化后, 先上传新的文件到OSS中, 再diff删除多余的文件.** \n\n## Cache-Control\n为上传的资源默认设置的`Cache-Control`如下\n|资源类型 | Cache-Control|\n|----| ----|\n|.html|no-cache|\n|.png/jpg...(图片资源)|max-age=864000(10days)|\n|other|max-age=2592000(30days)|\n\n## 静态页面配置\n默认的, action会将阿里云OSS的静态页面配置成如下\n![2020-08-06-03-18-25](https://image.fangbinwei.cn/github/aliyun-oss-website-action/2020-08-06-03-18-25_05d556d8.png)\n\n若不需要action来设置, 可以配置`skipSetting`为`true`\n\n## exclude\n如果`folder`下的某些文件不需要上传\n\n\n```yml\n    - name: exclude some files\n      uses: fangbinwei/aliyun-oss-website-action@v1\n      with:\n        folder: dist\n        exclude: |\n          tmp.txt\n          tmp/\n          tmp2/*.txt\n          tmp2/*/*.txt\n      # match dist/tmp.txt\n      # match dist/tmp/\n      # match dist/tmp2/a.txt\n      # match dist/tmp2/a/b.txt, not match dist/tmp2/tmp3/a/b.txt\n```\n\u003e 不支持`**`\n\n或者\n```yml\n- name: Clean files before upload\n  run: rm -f dist/tmp.txt\n```\n\n## Docker image\n直接使用已经build好的docker image\n```yml\n    - name: upload files to OSS\n      uses: docker://fangbinwei/aliyun-oss-website-action:v1\n      # 使用env而不是with, 参数可以见本项目的action.yml\n      env:\n          ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}\n          ACCESS_KEY_SECRET: ${{ secrets.ACCESS_KEY_SECRET }}\n          BUCKET: your-bucket-name\n          ENDPOINT: ali-oss-endpoint\n          FOLDER: your-website-output-folder\n```\n\n## Demo\n### 部署VuePress项目\n\n```yml\n\nname: deploy vuepress\n\non:\n  push:\n    branches:\n      - master\n\njobs:\n  build:\n\n    runs-on: ubuntu-latest\n    steps:\n      # load repo to /github/workspace\n    - uses: actions/checkout@v2\n      with:\n          repository: fangbinwei/blog\n          fetch-depth: 0\n    - name: Use Node.js\n      uses: actions/setup-node@v1\n      with:\n        node-version: '12'\n    - run: npm install yarn@1.22.4 -g\n    - run: yarn install\n    # 打包文档命令\n    - run: yarn docs:build\n    - name: upload files to OSS\n      uses: fangbinwei/aliyun-oss-website-action@v1\n      with:\n          accessKeyId: ${{ secrets.ACCESS_KEY_ID }}\n          accessKeySecret: ${{ secrets.ACCESS_KEY_SECRET }}\n          bucket: \"your-bucket-name\"\n          endpoint: \"oss-cn-shanghai.aliyuncs.com\" \n          folder: \".vuepress/dist\"\n```\n具体可以参考本项目的[workflow](.github/workflows/test.yml), npm/yarn配合`action/cache`加速依赖安装\n\n### Vue\n\n[see here](https://github.com/fangbinwei/oss-website-demo-spa-vue)\n\n```yml\n- name: upload files to OSS\n      uses: fangbinwei/aliyun-oss-website-action@v1\n      with:\n          accessKeyId: ${{ secrets.ACCESS_KEY_ID }}\n          accessKeySecret: ${{ secrets.ACCESS_KEY_SECRET }}\n          bucket: website-spa-vue-demo\n          endpoint: oss-spa-demo.fangbinwei.cn\n          cname: true\n          folder: dist\n          notFoundPage: index.html\n          htmlCacheControl: no-cache\n          imageCacheControl: max-age=864001\n          otherCacheControl: max-age=2592001\n```\n\n## FAQ\n\n### 配合CDN使用时, OSS更新后, CDN未刷新\n\n开启OSS提供的CDN缓存自动刷新功能, 将触发操作配置为`PutObject`, `DeleteObject`.\n\n![2020-12-13-23-51-28](https://image.fangbinwei.cn/github/aliyun-oss-website-action/2020-12-13-23-51-28_2c310155.png)\n\n![2020-12-13-23-51-55](https://image.fangbinwei.cn/github/aliyun-oss-website-action/2020-12-13-23-51-55_5fe79a54.png)\n\n### `endpoint`使用自定义域名, 但是无法上传\n1. 如果`endpoint`的域名CNAME记录为阿里云CDN, CDN是否配置了http强制跳转https? 若配置了, 需要在`endpoint`中指定https, 即`endpoint`为`https://example.org`\n\n2. 如果`endpoint`的域名CNAME记录为阿里云CDN, 在CDN为加速范围为全球时有遇到过如下报错`The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.`, 则`endpoint`不能使用自定义域名, 使用OSS源站的endpoint.\n\n### 配置了environment secret怎么不生效\n\n![2021-05-21-16-47-59](https://image.fangbinwei.cn/github/aliyun-oss-website-action/2021-05-21-16-47-59_affec2b0.png)\n\n如果使用environment secret, 那么需要如下类似的配置\n\n```diff\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n+    environment: your-environment-name\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffangbinwei%2Faliyun-oss-website-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffangbinwei%2Faliyun-oss-website-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffangbinwei%2Faliyun-oss-website-action/lists"}