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