gitea actions

This commit is contained in:
sillyguodong 2023-05-26 17:11:50 +08:00
parent faa280d3e6
commit 4334816812
No known key found for this signature in database
GPG Key ID: 4A0646FA86256DF4
1 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,49 @@
name: build and deploy website PR preview
env:
AWS_REGION: eu-central-1
on: [pull_request]
jobs:
build-and-deploy:
name: build and deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Hugo
uses: https://github.com/peaceiris/actions-hugo@v2
with:
hugo-version: "0.111.3"
extended: true
- name: Setup Go
uses: https://github.com/actions/setup-go@v4
with:
go-version: ">=1.20.1"
- name: Build
run: |
make clean
make build
- name: "[PR] create s3 bucket"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.preview_aws_access_token }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.preview_aws_secret_access_key }}
run: |
apk add --no-cache aws-cli
aws s3api create-bucket --acl public-read --bucket preview-gitea-org-website-${{ github.event.pull_request.head.repo.name }}-${{ github.event.pull_request.number }} --region ${{ env.AWS_REGION }}} --create-bucket-configuration LocationConstraint=${{ env.AWS_REGION }}} || /bin/true
aws s3 website s3://preview-gitea-org-website-${{ github.event.pull_request.head.repo.name }}-${{ github.event.pull_request.number }}/ --index-document index.html --error-document error.html || /bin/true
- name: "[PR] deploy website to S3 bucket"
uses: https://github.com/jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: preview-gitea-org-website-${{ github.event.pull_request.head.repo.name }}-${{ github.event.pull_request.number }}
AWS_ACCESS_KEY_ID: ${{ secrets.preview_aws_access_token }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.preview_aws_secret_access_key }}
AWS_REGION: ${{ env.AWS_REGION }}}
SOURCE_DIR: public/
DEST_DIR: /
- name: "[PR] Post comment to PR"
env:
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
'COMMENTS=$(curl -sL -X GET -H "Authorization: token $GITEA_TOKEN" https://gitea.com/api/v1/repos/${{ github.event.pull_request.head.repo.owner }}/${{ github.event.pull_request.head.repo.name }}/issues/${{ github.event.pull_request.number }}/comments)'
'if [[ $COMMENTS == "[]" ]]; then curl -sL -X POST -H "Authorization: token $GITEA_TOKEN" -H "Content-type: application/json" https://gitea.com/api/v1/repos/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME}/issues/${DRONE_PULL_REQUEST}/comments -d "{\"body\": \"Website preview: http://preview-gitea-org-website-${DRONE_REPO_NAME}-${DRONE_PULL_REQUEST}.s3-website.$${AWS_REGION}.amazonaws.com/\"}"; else echo -e "\n INFO: Comment already exist, doing nothing"; fi'