deploy-staging #26
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: Build and Deploy to Staging | |
concurrency: | |
group: staging | |
cancel-in-progress: true | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
repository_dispatch: | |
types: [deploy-staging] | |
jobs: | |
build: | |
name: Build Documentation | |
runs-on: ubuntu-latest | |
container: | |
image: ghcr.io/rocky-linux/docs-builder:latest | |
outputs: | |
DOCS_SHA: ${{ steps.build-docs.outputs.docs-sha }} | |
environment: staging | |
steps: | |
- name: Checkout mkdocs config | |
uses: actions/checkout@v4 | |
- name: Build Documentation | |
id: build-docs | |
uses: ./.github/actions/build-docs | |
- name: Archive build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-minified | |
path: build/minified | |
deploy: | |
name: Deploy to Staging | |
needs: build | |
runs-on: ubuntu-latest | |
container: | |
image: ghcr.io/rocky-linux/docs-builder:latest | |
environment: staging | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Restore cached build | |
uses: actions/cache/restore@v4 | |
id: docs-cache | |
with: | |
path: ${{ github.workspace }}/build/minified | |
key: cache-docs-default-${{ needs.build.outputs.DOCS_SHA }} | |
fail-on-cache-miss: false | |
enableCrossOsArchive: true | |
- name: Retrieve build artifacts | |
if: steps.docs-cache.outputs.cache-hit != 'true' | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-minified | |
path: build/minified | |
- name: Install Dependencies | |
run: npm install | |
working-directory: ./compute-js | |
- name: Cache fastly compute package | |
id: restore-fastly-cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ github.workspace }}/compute-js/pkg/*.tar.gz | |
key: cache-fastly-staging-${{ needs.build.outputs.DOCS_SHA }} | |
- name: Build Compute Package | |
if: steps.restore-fastly-cache.outputs.cache-hit != 'true' | |
run: npm run build | |
working-directory: ./compute-js | |
env: | |
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }} | |
- name: Publish to Staging Collection | |
run: | | |
npx @fastly/compute-js-static-publish publish-content | |
# --collection-name=staging \ | |
# --expires-in=7d \ | |
# --config=./publish-content.config.js | |
working-directory: ./compute-js | |
env: | |
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }} | |
- name: Output staging info | |
run: | | |
echo "🚀 Deployment completed!" | |
# echo "🚀 Staging deployment completed!" | |
# echo "📄 Collection: staging" | |
# echo "⏰ Expires: 7 days" | |
# echo "🔗 Access via your configured staging domain/collection selector" | |
- name: Notify documentation channel about deployment Success | |
uses: mattermost/action-mattermost-notify@master | |
if: success() && !cancelled() | |
with: | |
MATTERMOST_WEBHOOK_URL: ${{ secrets.MM_WEBHOOK_URL }} | |
MATTERMOST_CHANNEL: documentation | |
TEXT: | | |
[Deployment](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) was completed :white_check_mark: | |
MATTERMOST_USERNAME: "Github" | |
- name: Notify documentation channel about deployment Failure | |
uses: mattermost/action-mattermost-notify@master | |
if: failure() && !cancelled() | |
with: | |
MATTERMOST_WEBHOOK_URL: ${{ secrets.MM_WEBHOOK_URL }} | |
MATTERMOST_CHANNEL: documentation | |
TEXT: | | |
[Deployment](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) failed :x: | |
MATTERMOST_USERNAME: "Github" | |
auto-promote: | |
name: Auto-promote to Production | |
needs: [build, deploy] | |
runs-on: ubuntu-latest | |
container: | |
image: ghcr.io/rocky-linux/docs-builder:latest | |
environment: production | |
if: | | |
(vars.AUTO_DEPLOY_STAGING == 'true') || | |
(github.event_name == 'repository_dispatch' && github.event.client_payload.auto_deploy == 'true') | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install Dependencies | |
run: npm install | |
working-directory: ./compute-js | |
- name: Restore Fastly compute package cache | |
id: restore-fastly-cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ github.workspace }}/compute-js/pkg/*.tar.gz | |
key: cache-fastly-staging-${{ needs.build.outputs.DOCS_SHA }} | |
- name: Auto-promote staging to production | |
run: | | |
echo "🤖 Auto-promoting staging to production..." | |
npx @fastly/compute-js-static-publish collections promote \ | |
--collection-name=staging \ | |
--to=default \ | |
--expires-never | |
working-directory: ./compute-js | |
env: | |
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }} | |
- name: Output auto-promotion success | |
run: | | |
echo "🎉 Auto-promotion completed!" | |
echo "📄 Staging → Production (default collection)" | |
echo "⏰ Expires: never" | |
echo "🔗 Live at: https://docs.rockylinux.org" |