ci #1469
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: ci | |
| concurrency: | |
| cancel-in-progress: false | |
| group: ci-${{ github.ref_name }}-${{ github.event_name }} | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: "0 3 * * *" # Everyday, 10 WIB: building the site | |
| permissions: | |
| contents: write | |
| env: | |
| NETLIFY_SITE_ID: developer-friendly | |
| NETLIFY_DEPLOY_TO_PROD: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
| PYTHON_VERSION: 3.x | |
| ADSENSE_PROPERTY: ${{ vars.ADSENSE_PROPERTY }} | |
| GA_PROPERTY: ${{ vars.GA_PROPERTY }} | |
| LOGROCKET_PROPERTY: ${{ vars.LOGROCKET_PROPERTY }} | |
| jobs: | |
| preview: | |
| if: github.event_name == 'pull_request' && github.repository == 'developer-friendly/blog' | |
| permissions: | |
| pull-requests: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - env: | |
| GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
| name: Install dependencies | |
| run: | | |
| pip install -U pip -r requirements.txt | |
| sudo apt-get install -y libcairo2-dev libfreetype6-dev libffi-dev libjpeg-dev libpng-dev libz-dev pngquant | |
| - env: | |
| DRAFT: ${{ github.event_name == 'pull_request' }} | |
| PLAUSIBLE_BEARER_TOKEN: ${{ secrets.PLAUSIBLE_BEARER_TOKEN }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # git-committers plugin | |
| name: Build the site | |
| run: mkdocs build | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| name: build-pr${{ github.event.pull_request.number }} | |
| path: site | |
| - id: netlify | |
| name: Deploy to Netlify | |
| uses: jsmrcaga/[email protected] | |
| with: | |
| NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
| NETLIFY_DEPLOY_TO_PROD: ${{ env.NETLIFY_DEPLOY_TO_PROD }} | |
| NETLIFY_SITE_ID: ${{ env.NETLIFY_SITE_ID }} | |
| build_command: echo Skipping building the web files | |
| build_directory: site | |
| install_command: echo Skipping installing the dependencies | |
| - name: Comment PR | |
| uses: meysam81/comment-pr@main | |
| with: | |
| title: "# Live preview" | |
| content: | | |
| The live preview of the changes are available at the following URL: | |
| <${{ env.NETLIFY_PREVIEW_URL }}> | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| if: | | |
| github.repository == 'developer-friendly/blog' && | |
| ( | |
| ( | |
| github.event_name == 'push' && | |
| github.ref == 'refs/heads/main' | |
| ) || ( | |
| github.event_name == 'schedule' && | |
| github.event.schedule == '0 3 * * *' | |
| ) | |
| ) | |
| permissions: | |
| attestations: write | |
| contents: read | |
| id-token: write | |
| pages: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - env: | |
| GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
| name: Install dependencies | |
| run: | | |
| pip install -U pip -r requirements.txt | |
| sudo apt-get install -y libcairo2-dev libfreetype6-dev libffi-dev libjpeg-dev libpng-dev libz-dev pngquant | |
| - env: | |
| PLAUSIBLE_BEARER_TOKEN: ${{ secrets.PLAUSIBLE_BEARER_TOKEN }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| name: Build the site | |
| run: mkdocs build | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| name: build-${{ github.ref_name }}-${{ github.run_id }} | |
| path: site | |
| - id: deployment | |
| name: Deploy to GitHub Pages | |
| uses: actions/deploy-pages@v4 | |
| with: | |
| artifact_name: build-${{ github.ref_name }}-${{ github.run_id }} | |
| - if: ${{ github.repository == 'developer-friendly/blog' }} | |
| id: netlify | |
| name: Deploy to Netlify | |
| uses: jsmrcaga/[email protected] | |
| with: | |
| NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
| NETLIFY_DEPLOY_TO_PROD: ${{ env.NETLIFY_DEPLOY_TO_PROD }} | |
| NETLIFY_SITE_ID: ${{ env.NETLIFY_SITE_ID }} | |
| build_command: echo Skipping building the web files | |
| build_directory: site | |
| install_command: echo Skipping installing the dependencies | |
| lychee: | |
| if: | | |
| github.repository == 'developer-friendly/blog' && | |
| contains(fromJson('["schedule", "pull_request", "push"]'), github.event_name) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Calculate cache id | |
| run: echo "cache_id=$(date --utc '+%V')" >> "$GITHUB_ENV" | |
| - name: Cache lychee | |
| uses: actions/cache@v4 | |
| with: | |
| key: lychee-${{ env.cache_id }} | |
| path: .lycheecache | |
| restore-keys: | | |
| lychee- | |
| - id: lychee | |
| name: Link Checker | |
| uses: lycheeverse/lychee-action@v2 | |
| with: | |
| fail: ${{ github.ref == 'refs/heads/main' }} | |
| stale: | |
| if: | | |
| ( | |
| github.event_name == 'schedule' && | |
| github.repository == 'developer-friendly/blog' | |
| ) | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # only for delete-branch option | |
| issues: write | |
| pull-requests: write | |
| steps: | |
| - uses: actions/stale@v9 | |
| mirror: | |
| if: | | |
| github.repository == 'developer-friendly/blog' && | |
| contains(fromJson('["delete", "push"]'), github.event_name) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Mirror to GitLab | |
| run: | | |
| mkdir -p ~/.ssh | |
| cat <<'EOF' > ~/.ssh/config | |
| Host gitlab.com | |
| HostName gitlab.com | |
| User git | |
| IdentityFile ~/.ssh/id_rsa | |
| EOF | |
| cat <<'EOF' > ~/.ssh/id_rsa | |
| ${{ secrets.GITLAB_DEPLOY_KEY }} | |
| EOF | |
| chmod 600 ~/.ssh/id_rsa | |
| ssh-keyscan gitlab.com >> ~/.ssh/known_hosts | |
| git remote add gitlab [email protected]:developer-friendly/blog.git | |
| git push gitlab main |