From 43348168129ed87e2aced728d3c06bf82d47360a Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Fri, 26 May 2023 17:11:50 +0800 Subject: [PATCH] gitea actions --- .gitea/workflows/deploy-preview.yml | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .gitea/workflows/deploy-preview.yml diff --git a/.gitea/workflows/deploy-preview.yml b/.gitea/workflows/deploy-preview.yml new file mode 100644 index 0000000..99df3ef --- /dev/null +++ b/.gitea/workflows/deploy-preview.yml @@ -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'