Add Git identity configuration for deployment in GitHub Actions #2
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: Deploy portfolio to GitHub Pages | |
| on: | |
| push: | |
| branches: | |
| - master | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| - name: Cache npm | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.npm | |
| key: ${{ runner.os }}-node-${{ hashFiles('portfolio/package-lock.json', 'portfolio/pnpm-lock.yaml', 'portfolio/package.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| - name: Install dependencies (portfolio) | |
| run: npm install --prefix portfolio | |
| - name: Build (portfolio) | |
| run: npm run build --prefix portfolio | |
| - name: Configure Git identity for deploy | |
| env: | |
| DEPLOY_NAME: ${{ secrets.DEPLOY_NAME }} | |
| DEPLOY_EMAIL: ${{ secrets.DEPLOY_EMAIL }} | |
| run: | | |
| # Use provided secrets if available (set DEPLOY_NAME and DEPLOY_EMAIL in repo secrets), | |
| # otherwise fall back to the actor name and the actor noreply email | |
| if [ -n "$DEPLOY_NAME" ]; then | |
| git config --global user.name "$DEPLOY_NAME" | |
| else | |
| git config --global user.name "$GITHUB_ACTOR" | |
| fi | |
| if [ -n "$DEPLOY_EMAIL" ]; then | |
| git config --global user.email "$DEPLOY_EMAIL" | |
| else | |
| git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" | |
| fi | |
| - name: Deploy to gh-pages | |
| run: npm run gh-pages --prefix portfolio | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |