|
1 | | -name: Deploy Vue.js app to GitHub Pages |
| 1 | +# Workflow for building and deploying an Astro site to GitHub Pages |
| 2 | +# plus inclusion du site statique de la branche `old` dans /old |
| 3 | + |
| 4 | +name: Deploy Astro + Old site to GitHub Pages |
2 | 5 |
|
3 | 6 | on: |
4 | 7 | push: |
5 | | - branches: |
6 | | - - vue # Déploie quand tu pousses sur la branche 'vue' |
| 8 | + branches: ["master"] |
7 | 9 | workflow_dispatch: |
8 | 10 |
|
9 | 11 | permissions: |
10 | 12 | contents: read |
11 | 13 | pages: write |
12 | 14 | id-token: write |
13 | 15 |
|
| 16 | +concurrency: |
| 17 | + group: "pages" |
| 18 | + cancel-in-progress: false |
| 19 | + |
| 20 | +env: |
| 21 | + BUILD_PATH: "." # dossier du site Astro |
| 22 | + |
14 | 23 | jobs: |
15 | 24 | build: |
| 25 | + name: Build Astro site + include old version |
16 | 26 | runs-on: ubuntu-latest |
17 | | - |
18 | 27 | steps: |
19 | | - - name: Checkout repository |
| 28 | + - name: Checkout master (Astro site) |
20 | 29 | uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + ref: master |
| 32 | + |
| 33 | + - name: Detect package manager |
| 34 | + id: detect-package-manager |
| 35 | + run: | |
| 36 | + if [ -f "${{ github.workspace }}/yarn.lock" ]; then |
| 37 | + echo "manager=yarn" >> $GITHUB_OUTPUT |
| 38 | + echo "command=install" >> $GITHUB_OUTPUT |
| 39 | + echo "runner=yarn" >> $GITHUB_OUTPUT |
| 40 | + echo "lockfile=yarn.lock" >> $GITHUB_OUTPUT |
| 41 | + elif [ -f "${{ github.workspace }}/package.json" ]; then |
| 42 | + echo "manager=npm" >> $GITHUB_OUTPUT |
| 43 | + echo "command=ci" >> $GITHUB_OUTPUT |
| 44 | + echo "runner=npx --no-install" >> $GITHUB_OUTPUT |
| 45 | + echo "lockfile=package-lock.json" >> $GITHUB_OUTPUT |
| 46 | + else |
| 47 | + echo "Unable to determine package manager" |
| 48 | + exit 1 |
| 49 | + fi |
21 | 50 |
|
22 | | - - name: Setup Node.js |
| 51 | + - name: Setup Node |
23 | 52 | uses: actions/setup-node@v4 |
24 | 53 | with: |
25 | | - node-version: 18 # Compatible avec Vue 3/Vite |
26 | | - |
| 54 | + node-version: "20" |
| 55 | + cache: ${{ steps.detect-package-manager.outputs.manager }} |
| 56 | + cache-dependency-path: ${{ env.BUILD_PATH }}/${{ steps.detect-package-manager.outputs.lockfile }} |
| 57 | + |
27 | 58 | - name: Setup Pages |
28 | 59 | id: pages |
29 | 60 | uses: actions/configure-pages@v5 |
30 | | - |
| 61 | + |
31 | 62 | - name: Install dependencies |
32 | | - run: npm install |
| 63 | + run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} |
| 64 | + working-directory: ${{ env.BUILD_PATH }} |
| 65 | + |
| 66 | + - name: Build Astro site |
| 67 | + run: | |
| 68 | + ${{ steps.detect-package-manager.outputs.runner }} astro build \ |
| 69 | + --site "${{ steps.pages.outputs.origin }}" \ |
| 70 | + --base "${{ steps.pages.outputs.base_path }}" |
| 71 | + working-directory: ${{ env.BUILD_PATH }} |
| 72 | + |
| 73 | + - name: Clone old branch (static site) |
| 74 | + run: | |
| 75 | + git clone --depth 1 --branch old https://github.com/${{ github.repository }} tmp-old |
| 76 | + mkdir -p ${{ env.BUILD_PATH }}/dist/old |
| 77 | + cp -r tmp-old/* ${{ env.BUILD_PATH }}/dist/old/ || true |
| 78 | + rm -rf tmp-old |
33 | 79 |
|
34 | | - - name: Build project |
35 | | - run: npm run build |
36 | | - |
37 | 80 | - name: Upload artifact |
38 | 81 | uses: actions/upload-pages-artifact@v3 |
39 | 82 | with: |
40 | | - path: ./dist |
| 83 | + path: ${{ env.BUILD_PATH }}/dist |
41 | 84 |
|
42 | 85 | deploy: |
43 | | - needs: build |
44 | | - runs-on: ubuntu-latest |
| 86 | + name: Deploy to GitHub Pages |
45 | 87 | environment: |
46 | 88 | name: github-pages |
47 | 89 | url: ${{ steps.deployment.outputs.page_url }} |
| 90 | + needs: build |
| 91 | + runs-on: ubuntu-latest |
48 | 92 | steps: |
49 | 93 | - name: Deploy to GitHub Pages |
50 | 94 | id: deployment |
|
0 commit comments