Deploy Home #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Home | |
| # Controls when the action will run. | |
| on: | |
| push: | |
| branches: [ main, production ] | |
| paths: | |
| - 'content/*' | |
| pull_request: | |
| branches: [ main, production ] | |
| repository_dispatch: | |
| types: [staging-complete, production-complete] | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: 'Branch to check out' | |
| required: false | |
| default: 'main' | |
| environment: | |
| description: 'Target environment' | |
| required: false | |
| type: choice | |
| options: | |
| - qa | |
| - prod | |
| default: qa | |
| deployment_target: | |
| description: 'Deployment target' | |
| required: true | |
| default: 's3' | |
| type: choice | |
| options: | |
| - s3 | |
| - ceph | |
| # A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
| jobs: | |
| deploy: | |
| name: Deploy ${{ (github.event_name == 'workflow_dispatch' && inputs.environment) || (github.event_name == 'repository_dispatch' && github.event.action == 'production-complete' && 'prod') || (github.ref == 'refs/heads/production' && 'prod') || 'qa' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Resolve inputs and environment | |
| id: vars | |
| shell: bash | |
| env: | |
| INPUT_BRANCH: ${{ inputs.branch }} | |
| INPUT_ENVIRONMENT: ${{ inputs.environment }} | |
| REF_NAME: ${{ github.ref_name }} | |
| CEPH_QA_ACCESS_KEY_ID: ${{ secrets.CEPH_QA_ACCESS_KEY_ID }} | |
| CEPH_QA_SECRET_ACCESS_KEY: ${{ secrets.CEPH_QA_SECRET_ACCESS_KEY }} | |
| CEPH_PROD_ACCESS_KEY_ID: ${{ secrets.CEPH_PROD_ACCESS_KEY_ID }} | |
| CEPH_PROD_SECRET_ACCESS_KEY: ${{ secrets.CEPH_PROD_SECRET_ACCESS_KEY }} | |
| run: | | |
| BRANCH="$INPUT_BRANCH" | |
| if [ -z "$BRANCH" ]; then | |
| BRANCH="$REF_NAME" | |
| fi | |
| if [ -z "$INPUT_ENVIRONMENT" ]; then | |
| if [ "$REF_NAME" = "production" ]; then | |
| ENVIRONMENT="prod" | |
| else | |
| ENVIRONMENT="qa" | |
| fi | |
| else | |
| ENVIRONMENT="$INPUT_ENVIRONMENT" | |
| fi | |
| if [ "$ENVIRONMENT" = "prod" ]; then | |
| CONFIG_FILE="./config-prod.toml" | |
| BASE_URL="https://products.groupdocs.com" | |
| SITEMAP_SRC="sitemaps.xml" | |
| WEBSITE="https://products.groupdocs.com/*" | |
| CEPH_ACCESS_KEY_ID="$CEPH_PROD_ACCESS_KEY_ID" | |
| CEPH_SECRET_ACCESS_KEY="$CEPH_PROD_SECRET_ACCESS_KEY" | |
| else | |
| CONFIG_FILE="./config-qa.toml" | |
| BASE_URL="https://products-qa.groupdocs.com/" | |
| SITEMAP_SRC="sitemaps-qa.xml" | |
| WEBSITE="https://products-qa.groupdocs.com/*" | |
| CEPH_ACCESS_KEY_ID="$CEPH_QA_ACCESS_KEY_ID" | |
| CEPH_SECRET_ACCESS_KEY="$CEPH_QA_SECRET_ACCESS_KEY" | |
| fi | |
| echo "branch=$BRANCH" >> $GITHUB_OUTPUT | |
| echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT | |
| echo "config_file=$CONFIG_FILE" >> $GITHUB_OUTPUT | |
| echo "base_url=$BASE_URL" >> $GITHUB_OUTPUT | |
| echo "sitemap_src=$SITEMAP_SRC" >> $GITHUB_OUTPUT | |
| echo "website=$WEBSITE" >> $GITHUB_OUTPUT | |
| echo "ceph_access_key_id=$CEPH_ACCESS_KEY_ID" >> $GITHUB_OUTPUT | |
| echo "ceph_secret_access_key=$CEPH_SECRET_ACCESS_KEY" >> $GITHUB_OUTPUT | |
| # Step 1 - Checks-out your repository under $GITHUB_WORKSPACE | |
| - name: Checkout theme repo | |
| uses: actions/checkout@main | |
| with: | |
| repository: groupdocs/products.groupdocs.com | |
| token: ${{ secrets.REPO_TOKEN }} | |
| fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod | |
| ref: ${{ steps.vars.outputs.branch }} | |
| # Step 2 - Sets up the latest version of Hugo | |
| - name: Setup Hugo | |
| uses: peaceiris/actions-hugo@v2 | |
| with: | |
| hugo-version: '0.101.0' | |
| extended: true | |
| - name: Make Content folder for HomePage | |
| run: | | |
| cp -R content content_new; | |
| rm -R content; | |
| mkdir content; | |
| cp content_new/_index.en.md content; | |
| cp content_new/_index.de.md content; | |
| cp content_new/_index.es.md content; | |
| cp content_new/_index.fa.md content; | |
| cp content_new/_index.fr.md content; | |
| cp content_new/_index.id.md content; | |
| cp content_new/_index.it.md content; | |
| cp content_new/_index.ja.md content; | |
| cp content_new/_index.ko.md content; | |
| cp content_new/_index.pt.md content; | |
| cp content_new/_index.ru.md content; | |
| cp content_new/_index.th.md content; | |
| cp content_new/_index.uk.md content; | |
| cp content_new/_index.vi.md content; | |
| cp content_new/_index.zh.md content; | |
| - name: Build Home | |
| run: hugo --config "${{ steps.vars.outputs.config_file }}" -c "content" -b "${{ steps.vars.outputs.base_url }}" --disableKinds=page,section --minify | |
| - name: Copy static sitemap to public folder | |
| run: | | |
| cp ${{ steps.vars.outputs.sitemap_src }} public/sitemaps.xml; | |
| - name: Deploy Home to S3 | |
| if: github.event_name == 'workflow_dispatch' && inputs.deployment_target == 's3' || github.event_name != 'workflow_dispatch' | |
| run: hugo deploy --config "${{ steps.vars.outputs.config_file }}" --target "Home" --maxDeletes 0 | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS }} | |
| - name: Deploy Home to Ceph | |
| if: github.event_name == 'workflow_dispatch' && inputs.deployment_target == 'ceph' | |
| run: hugo deploy --config "${{ steps.vars.outputs.config_file }}" --target "Home-ceph" --maxDeletes 0 | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ steps.vars.outputs.ceph_access_key_id }} | |
| AWS_SECRET_ACCESS_KEY: ${{ steps.vars.outputs.ceph_secret_access_key }} | |
| - name: Invalidate cache | |
| env: | |
| API_ENDPOINT: ${{ secrets.CACHE_INVALIDATION_API_ENDPOINT }} | |
| WEBSITE: ${{ steps.vars.outputs.website }} | |
| run: | | |
| curl --write-out '%{http_code}' --silent --output /dev/null -d "{\"website\":\"$WEBSITE\"}" -H "Content-Type: application/json" -X POST "$API_ENDPOINT" | |
| - name: Invalidate BunnyNet cache | |
| env: | |
| BUNNYNET_ACCESS_KEY: ${{ secrets.BUNNYNET_ACCESS_KEY }} | |
| BUNNYNET_PURGE_URL: ${{ secrets.BUNNYNET_PURGE_URL }} | |
| run: | | |
| BASEURL="${{ steps.vars.outputs.website }}" | |
| curl -siG -H "X-Api-Key: $BUNNYNET_ACCESS_KEY" --data-urlencode "url=$BASEURL" "$BUNNYNET_PURGE_URL" |