Merge branch 'main' of https://github.com/Boutzi/oc-integrateur-web-p12 #114
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 Next.js PORTFOLIO to Pages | |
on: | |
push: | |
branches: ["main"] | |
workflow_dispatch: | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
concurrency: | |
group: "pages" | |
cancel-in-progress: false | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Detect package manager | |
id: detect-package-manager | |
run: | | |
if [ -f "${{ github.workspace }}/yarn.lock" ]; then | |
echo "manager=yarn" >> $GITHUB_OUTPUT | |
echo "command=install" >> $GITHUB_OUTPUT | |
echo "runner=yarn" >> $GITHUB_OUTPUT | |
exit 0 | |
elif [ -f "${{ github.workspace }}/package.json" ]; then | |
echo "manager=npm" >> $GITHUB_OUTPUT | |
echo "command=ci" >> $GITHUB_OUTPUT | |
echo "runner=npx --no-install" >> $GITHUB_OUTPUT | |
exit 0 | |
else | |
echo "Unable to determine package manager" | |
exit 1 | |
fi | |
- name: Git config | |
run: | | |
git config --local user.name "boutzi" | |
git config --local user.email "[email protected]" | |
git pull | |
- name: Increment version (package.json) | |
id: increment_version | |
run: | | |
if [[ "${{ github.event.head_commit.message }}" == *"Merge"* ]]; then | |
echo "Ceci est un commit de fusion, aucune action sur la version." | |
exit 0 | |
fi | |
CURRENT_VERSION=$(jq -r '.version' package.json) | |
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION" | |
echo "Version actuelle: $CURRENT_VERSION" | |
if [[ "${{ github.event.head_commit.message }}" == *"major"* ]]; then | |
major=$((major + 1)) | |
minor=0 | |
patch=0 | |
elif [[ "${{ github.event.head_commit.message }}" == *"feat"* ]]; then | |
minor=$((minor + 1)) | |
patch=0 | |
elif [[ "${{ github.event.head_commit.message }}" == *"fix"* ]]; then | |
patch=$((patch + 1)) | |
else | |
echo "Aucun incrément de version spécifié. Aucune modification." | |
exit 0 | |
fi | |
NEW_VERSION="$major.$minor.$patch" | |
echo "Nouvelle version: $NEW_VERSION" | |
jq --arg new_version "$NEW_VERSION" '.version = $new_version' package.json > tmp.$$.json && mv tmp.$$.json package.json | |
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV | |
- name: Commit and push new version | |
run: | | |
git add package.json | |
git commit -m "Bump version to ${{ env.new_version }}" || echo "Aucune modification à valider." | |
git push origin main || echo "Échec du push, vérifiez les permissions." | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: ${{ steps.detect-package-manager.outputs.manager }} | |
- name: Setup Pages | |
uses: actions/configure-pages@v5 | |
with: | |
static_site_generator: next | |
- name: Restore cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
.next/cache | |
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} | |
restore-keys: | | |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}- | |
- name: Install dependencies | |
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} | |
- name: Next.js build | |
run: ${{ steps.detect-package-manager.outputs.runner }} next build | |
env: | |
NEXT_PUBLIC_GITHUB_BEARER_TOKEN: ${{ secrets.NEXT_PUBLIC_GITHUB_BEARER_TOKEN }} | |
NEXT_PUBLIC_APIKEY: ${{ secrets.NEXT_PUBLIC_APIKEY }} | |
NEXT_PUBLIC_AUTHDOMAIN: ${{ secrets.NEXT_PUBLIC_AUTHDOMAIN }} | |
NEXT_PUBLIC_PROJECTID: ${{ secrets.NEXT_PUBLIC_PROJECTID }} | |
NEXT_PUBLIC_STORAGEBUCKET: ${{ secrets.NEXT_PUBLIC_STORAGEBUCKET }} | |
NEXT_PUBLIC_MESSAGINGSENDERID: ${{ secrets.NEXT_PUBLIC_MESSAGINGSENDERID }} | |
NEXT_PUBLIC_APPID: ${{ secrets.NEXT_PUBLIC_APPID }} | |
NEXT_PUBLIC_MEASUREMENTID: ${{ secrets.NEXT_PUBLIC_MEASUREMENTID }} | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: ./out | |
deploy: | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |