Refactor workflows

- Update webpack.yml and deploy-docs.yml to use GitHub App tokens
- Ensure consistent token usage for all git operations
- Add proper checkout configuration with fetch-depth
- Standardize environment variables and job structure
- Add timeouts to prevent hanging workflows
- Improve change detection for relevant files
This commit is contained in:
DigiLive
2025-05-29 08:56:10 +02:00
parent 6a2e64f6ad
commit 95794bf3b8
2 changed files with 51 additions and 28 deletions

View File

@@ -12,19 +12,18 @@ permissions:
contents: write
jobs:
check-for-docs-changes:
name: Check for Docs Changes
check-for-changes:
name: Check for changes
runs-on: ubuntu-latest
outputs:
# Output a boolean indicating if any relevant files have changed
docs_changed: ${{ steps.check_files.outputs.any_changed }}
changed: ${{ steps.check_files.outputs.any_changed }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for changed files in docs folder or mkdocs.yml
- name: Check for changed documentation files
id: check_files
uses: tj-actions/changed-files@v46
with:
@@ -35,22 +34,39 @@ jobs:
deploy:
name: Deploy MkDocs Site
runs-on: ubuntu-latest
needs: check-for-docs-changes
if: needs.check-for-docs-changes.outputs.docs_changed == 'true'
timeout-minutes: 10
needs: check-for-changes
if: needs.check-for-changes.outputs.changed == 'true'
env:
CI_COMMIT_AUTHOR: 'CI Bot'
CI_COMMIT_EMAIL: 'ci@noreply.github.com'
CI_COMMIT_MESSAGE: 'Continuous Integration - Deploy Documentation'
steps:
- name: Generate GitHub App Token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ steps.generate_token.outputs.token }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x' # Use a specific version like '3.10', '3.11', or '3.12'
python-version: '3.x'
- name: Install MkDocs, Material for MkDocs, and PyMdown Extensions
- name: Install MkDocs and dependencies
run: pip install mkdocs mkdocs-material pymdown-extensions
- name: Deploy Docs to GitHub Pages
run: mkdocs gh-deploy --force --clean
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_GIT_ACCESS_TOKEN }}
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "${{ env.CI_COMMIT_EMAIL }}"
git remote set-url origin https://x-access-token:${{ steps.generate_token.outputs.token }}@github.com/DigiLive/mushroom-strategy.git
mkdocs gh-deploy --force --clean --message "${{ env.CI_COMMIT_MESSAGE }}"

View File

@@ -6,19 +6,18 @@ on:
- main
jobs:
detect-source-changes:
name: Detect Source Changes
check-for-changes:
name: Check for changes
runs-on: ubuntu-latest
outputs:
source_changed: ${{ steps.check_files.outputs.any_changed }}
changed: ${{ steps.check_files.outputs.any_changed }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.WORKFLOW_GIT_ACCESS_TOKEN }}
- name: Check for changed files in src or webpack.config.js
- name: Check for changed source files
id: check_files
uses: tj-actions/changed-files@v46
with:
@@ -29,43 +28,51 @@ jobs:
build:
name: Build Distribution
runs-on: ubuntu-latest
timeout-minutes: 10
needs: check-for-changes
if: needs.check-for-changes.outputs.changed == 'true'
env:
CI_COMMIT_AUTHOR: 'CI Bot'
CI_COMMIT_EMAIL: 'ci@noreply.github.com'
CI_COMMIT_MESSAGE: |
Continuous Integration - Build Distribution
[skip codacy]
CI_COMMIT_AUTHOR: Continuous Integration
strategy:
matrix:
node-version: [22.x]
needs: detect-source-changes
if: needs.detect-source-changes.outputs.source_changed == 'true'
steps:
- name: Generate GitHub App Token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.WORKFLOW_GIT_ACCESS_TOKEN }}
token: ${{ steps.generate_token.outputs.token }}
fetch-depth: 0
# Build steps
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Node Install
- name: Install Dependencies
run: npm ci
- name: Build Distribution
run: |
npm run build
run: npm run build
- name: Commit Distribution Build
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "ci_activity@noreply.github.com"
git config --global user.email "${{ env.CI_COMMIT_EMAIL }}"
git remote set-url origin https://x-access-token:${{ steps.generate_token.outputs.token }}@github.com/DigiLive/mushroom-strategy.git
git add dist
git commit -m "${{ env.CI_COMMIT_MESSAGE }}"
git push