|
| 1 | +name: 🏢 Update Annuaire Entreprises |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 2 * * *" # Daily at 2 AM UTC |
| 6 | + pull_request: |
| 7 | + paths: |
| 8 | + - "packages/annuaire_entreprises/scripts/build-data.ts" |
| 9 | + - ".github/workflows/update-annuaire.yml" |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + update: |
| 14 | + name: 🔄 Update data files |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: write |
| 18 | + pull-requests: write |
| 19 | + env: |
| 20 | + DRY_RUN: ${{ github.event_name == 'pull_request' }} |
| 21 | + steps: |
| 22 | + - name: 📥 Checkout repository |
| 23 | + uses: actions/checkout@v5 |
| 24 | + |
| 25 | + - name: ⚙️ Enable corepack |
| 26 | + run: corepack enable |
| 27 | + |
| 28 | + - name: 📦 Setup Node.js |
| 29 | + uses: actions/setup-node@v5 |
| 30 | + with: |
| 31 | + cache: "npm" |
| 32 | + node-version-file: package.json |
| 33 | + |
| 34 | + - name: 📥 Install dependencies |
| 35 | + run: npm ci |
| 36 | + |
| 37 | + - name: 🔍 Get latest commit from search-infra |
| 38 | + id: latest |
| 39 | + run: | |
| 40 | + LATEST_COMMIT=$(git ls-remote https://github.com/annuaire-entreprises-data-gouv-fr/search-infra.git HEAD | cut -f1) |
| 41 | + echo "commit=$LATEST_COMMIT" >> $GITHUB_OUTPUT |
| 42 | + echo "short_commit=${LATEST_COMMIT:0:7}" >> $GITHUB_OUTPUT |
| 43 | +
|
| 44 | + - name: 📋 Get current commit |
| 45 | + id: current |
| 46 | + run: | |
| 47 | + CURRENT=$(cat packages/annuaire_entreprises/data/.commit) |
| 48 | + echo "commit=$CURRENT" >> $GITHUB_OUTPUT |
| 49 | + echo "short_commit=${CURRENT:0:7}" >> $GITHUB_OUTPUT |
| 50 | +
|
| 51 | + - name: ✅ Check if update needed |
| 52 | + id: check |
| 53 | + run: | |
| 54 | + if [ "${{ steps.latest.outputs.commit }}" != "${{ steps.current.outputs.commit }}" ]; then |
| 55 | + echo "needs_update=true" >> $GITHUB_OUTPUT |
| 56 | + else |
| 57 | + echo "needs_update=false" >> $GITHUB_OUTPUT |
| 58 | + fi |
| 59 | +
|
| 60 | + - name: 📦 Update commit reference |
| 61 | + if: steps.check.outputs.needs_update == 'true' |
| 62 | + run: | |
| 63 | + echo "${{ steps.latest.outputs.commit }}" > packages/annuaire_entreprises/data/.commit |
| 64 | +
|
| 65 | + - name: 🔄 Rebuild data files |
| 66 | + if: steps.check.outputs.needs_update == 'true' |
| 67 | + run: npm run build:data |
| 68 | + working-directory: packages/annuaire_entreprises |
| 69 | + |
| 70 | + - name: 🔍 Check for data changes |
| 71 | + if: steps.check.outputs.needs_update == 'true' |
| 72 | + id: data_check |
| 73 | + run: | |
| 74 | + if git diff --quiet packages/annuaire_entreprises/data/*.json; then |
| 75 | + echo "needs_update=false" >> $GITHUB_OUTPUT |
| 76 | + else |
| 77 | + echo "needs_update=true" >> $GITHUB_OUTPUT |
| 78 | + fi |
| 79 | +
|
| 80 | + - name: 🏷️ Show update summary |
| 81 | + if: steps.data_check.outputs.needs_update == 'true' |
| 82 | + run: | |
| 83 | + echo "📊 Update Summary:" |
| 84 | + echo " Current: ${{ steps.current.outputs.short_commit }}" |
| 85 | + echo " Latest: ${{ steps.latest.outputs.short_commit }}" |
| 86 | + echo " Dry run: ${{ env.DRY_RUN }}" |
| 87 | +
|
| 88 | + - name: 📋 Show data diff |
| 89 | + if: steps.data_check.outputs.needs_update == 'true' |
| 90 | + run: | |
| 91 | + echo "::group::📊 Data changes" |
| 92 | + git diff --stat packages/annuaire_entreprises/data/ |
| 93 | + echo "" |
| 94 | + git diff packages/annuaire_entreprises/data/ |
| 95 | + echo "::endgroup::" |
| 96 | +
|
| 97 | + - name: 📝 Create changeset |
| 98 | + if: steps.data_check.outputs.needs_update == 'true' |
| 99 | + run: | |
| 100 | + mkdir -p .changeset |
| 101 | + cat << EOF > .changeset/update-annuaire-${{ steps.latest.outputs.short_commit }}.md |
| 102 | + --- |
| 103 | + "@proconnect-gouv/proconnect.annuaire_entreprises": patch |
| 104 | + --- |
| 105 | +
|
| 106 | + ⬆️ Mise à jour des données annuaire entreprises depuis search-infra@${{ steps.latest.outputs.short_commit }} |
| 107 | + EOF |
| 108 | +
|
| 109 | + - name: 🔀 Create Pull Request |
| 110 | + if: steps.data_check.outputs.needs_update == 'true' && env.DRY_RUN != 'true' |
| 111 | + uses: peter-evans/create-pull-request@v7 |
| 112 | + with: |
| 113 | + add-paths: | |
| 114 | + .changeset/*.md |
| 115 | + packages/annuaire_entreprises/data/.commit |
| 116 | + packages/annuaire_entreprises/data/*.json |
| 117 | + author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>" |
| 118 | + branch: github-actions/update-annuaire-${{ steps.latest.outputs.short_commit }} |
| 119 | + commit-message: "⬆️ bump annuaire-entreprises-data-gouv-fr/search-infra@${{ steps.latest.outputs.short_commit }}" |
| 120 | + delete-branch: true |
| 121 | + title: "⬆️ bump annuaire-entreprises-data-gouv-fr/search-infra@${{ steps.latest.outputs.short_commit }}" |
| 122 | + body: | |
| 123 | + <div align=center><img src="https://annuaire-entreprises.data.gouv.fr/images/linkedin.jpg" /></div> |
| 124 | +
|
| 125 | + --- |
| 126 | +
|
| 127 | + Automated update of `@annuaire-entreprises-data-gouv-fr/search-infra` from ${{ steps.current.outputs.short_commit }} to ${{ steps.latest.outputs.short_commit }}. |
0 commit comments