Deploy to Production - push #50
This file contains 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 to Production | |
run-name: ${{ github.workflow }} - ${{ github.event_name }} | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
env: | |
ARTIFACT: deployment-artifact | |
GHPAGES_BRANCH: gh-pages-hugo | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Build Hugo Website | |
uses: ./.github/actions/build-hugo-website | |
with: | |
env: production | |
build-artifact: ${{ env.ARTIFACT }} | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT }} | |
path: ${{ env.ARTIFACT }} | |
retention-days: 1 | |
# I need to checkout the ${{env.GHPAGES_BRANCH}} branch with the built website content, | |
# and then download the artifact from the build job into it. | |
# This will ultimately change/add some files — things I need to commit and push back to the branch. | |
# And this is where passing the artifacts between jobs makes sense. | |
deploy: | |
needs: [build] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the branch for website hosting | |
uses: actions/checkout@v4 | |
with: | |
ref: '${{ env.GHPAGES_BRANCH }}' | |
- name: Get the new website content | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT }} | |
path: ./ | |
retention-days: 1 | |
- name: Deploy website | |
run: | | |
set -ex | |
if [[ -z $(git status --porcelain) ]]; then | |
echo "No changes to the site were detected" | |
else | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "${GITHUB_ACTOR}@bots.github.com" | |
git add -A | |
git commit -a -m "Website deploy — ${GITHUB_RUN_NUMBER}" | |
git remote set-url origin "https://x-access-token:${{ secrets.DEPLOY_TOKEN }}@github.com/vasylenko/devdosvid.blog.git" | |
git push --force origin ${{ env.GHPAGES_BRANCH }} | |
fi | |
purge-cache: | |
needs: [deploy] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Send API request to CloudFlare | |
run: | | |
set -ex | |
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLAREZONEID }}/purge_cache" \ | |
-H "Authorization: Bearer ${{ secrets.CLOUDFLAREPURGETOKEN }}" \ | |
-H "Content-Type: application/json" \ | |
--data '{"purge_everything":true}' | jq '.success' |