Eng - Build and Deploy #5250
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: Eng - Build and Deploy | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| # Here are the times for the cron: | |
| # | |
| # Sun, Mon, Tue, Thu, Fri : at 00:00, 03:00, 06:00, 09:00, 12:00, 15:00, 18:00, 21:00 UTC | |
| # Wed, Sat : at --:--, --:--, 06:00, 09:00, 12:00, 15:00, 18:00, 21:00 UTC | |
| # | |
| # There is a 6 hour maintenance window on Wednesdays and Saturdays, | |
| # and the crons are scheduled at 5 mins past the hour. | |
| # | |
| - cron: '5 0,3,6,9,12,15,18,21 * * 0-2,4-5' | |
| - cron: '5 6,9,12,15,18,21 * * 3,6' | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-24.04 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| node-version: [24.x] | |
| languages: [english] | |
| site_tlds: [org] | |
| env: | |
| BUILD_LANG: ${{ matrix.languages }} | |
| ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }} | |
| ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }} | |
| CHAT_WEBHOOK_KEY: ${{ secrets.CHAT_WEBHOOK_KEY }} | |
| CHAT_WEBHOOK_TOKEN: ${{ secrets.CHAT_WEBHOOK_TOKEN }} | |
| ENGLISH_GHOST_API_URL: ${{ secrets.ENGLISH_GHOST_API_URL }} | |
| ENGLISH_GHOST_API_VERSION: ${{ secrets.ENGLISH_GHOST_API_VERSION }} | |
| ENGLISH_GHOST_CONTENT_API_KEY: ${{ secrets.ENGLISH_GHOST_CONTENT_API_KEY }} | |
| ADS_ENABLED: ${{ secrets.ADS_ENABLED }} | |
| GOOGLE_ADSENSE_DATA_AD_CLIENT: ${{ secrets.GOOGLE_ADSENSE_DATA_AD_CLIENT }} | |
| GOOGLE_ADSENSE_DATA_AD_SLOT: ${{ secrets.GOOGLE_ADSENSE_DATA_AD_SLOT }} | |
| HASHNODE_API_URL: ${{ secrets.HASHNODE_API_URL }} | |
| ENGLISH_HASHNODE_HOST: ${{ secrets.ENGLISH_HASHNODE_HOST }} | |
| POSTS_PER_PAGE: ${{ secrets.POSTS_PER_PAGE }} | |
| SITE_DOMAIN: freecodecamp.${{ matrix.site_tlds }} | |
| LOCALE_FOR_UI: ${{ matrix.languages }} | |
| LOCALE_FOR_GHOST: ${{ matrix.languages }} | |
| DO_NOT_FETCH_FROM_GHOST: true | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6 | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build site | |
| run: | | |
| pnpm run build || { | |
| echo "::warning::Build failed after in-app retries exhausted. Waiting 2 minutes before final job-level retry..." | |
| sleep 120 | |
| echo "::notice::Retrying build site step..." | |
| pnpm run build | |
| } | |
| env: | |
| NODE_ENV: production | |
| - name: Create a tagname | |
| id: tagname | |
| run: | | |
| echo "tagname=$(git rev-parse --short HEAD)-$(date +%Y%m%d)-$(date +%H%M)" >> $GITHUB_ENV | |
| - name: Build & Tag Images | |
| run: | | |
| docker build . \ | |
| --tag registry.digitalocean.com/${{ secrets.DOCR_NAME }}/${{ matrix.site_tlds }}/news-${{ matrix.languages }}:$tagname \ | |
| --tag registry.digitalocean.com/${{ secrets.DOCR_NAME }}/${{ matrix.site_tlds }}/news-${{ matrix.languages }}:latest \ | |
| --build-arg BUILD_LANGUAGE=${{ matrix.languages }} \ | |
| --file docker/Dockerfile | |
| - name: Install doctl | |
| uses: digitalocean/action-doctl@3cb3953159719656269e044e0e24ca16dd2a690f # v2.5.2 | |
| with: | |
| token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | |
| - name: Log in to DigitalOcean Container Registry with short-lived credentials | |
| run: doctl registry login --expiry-seconds 1200 | |
| - name: Push image to DigitalOcean Container Registry | |
| run: | | |
| docker push registry.digitalocean.com/${{ secrets.DOCR_NAME }}/${{ matrix.site_tlds }}/news-${{ matrix.languages }}:$tagname | |
| docker push registry.digitalocean.com/${{ secrets.DOCR_NAME }}/${{ matrix.site_tlds }}/news-${{ matrix.languages }}:latest | |
| # - name: Clean up Self-hosted setup | |
| # uses: colpal/actions-clean@36e6ca1abd35efe61cb60f912bd7837f67887c8a # tag=v1 | |
| # if: ${{ always() }} # To ensure this step runs even when earlier steps fail | |
| # Deployments are automated via https://github.com/freeCodeCamp/news-docker-swarm-config |