feat: externalize packages for i18nify-go #147
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: Auto-Generate Go Packages | |
| on: | |
| pull_request: | |
| types: [opened, synchronize] | |
| branches: | |
| - master | |
| paths: | |
| - 'i18nify-data/country/subdivisions/**' | |
| - 'i18nify-data/currency/**' | |
| - 'i18nify-data/bankcodes/**' | |
| - 'i18nify-data/country/metadata/**' | |
| - '!i18nify-data/go/**' | |
| push: | |
| branches: | |
| - master | |
| paths: | |
| - 'i18nify-data/country/subdivisions/**' | |
| - 'i18nify-data/currency/**' | |
| - 'i18nify-data/bankcodes/**' | |
| - 'i18nify-data/country/metadata/**' | |
| - '!i18nify-data/go/**' | |
| # Manual trigger via GitHub Actions UI | |
| workflow_dispatch: | |
| inputs: | |
| package: | |
| description: 'Package to generate' | |
| required: false | |
| type: choice | |
| default: 'all' | |
| options: | |
| - 'all' | |
| - 'country/subdivisions' | |
| - 'currency' | |
| - 'bankcodes' | |
| - 'country/metadata' | |
| branch: | |
| description: 'Branch to run on' | |
| required: true | |
| default: 'master' | |
| concurrency: | |
| group: auto-generate-go-${{ github.event_name }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| # For PR/push: detect which packages have data changes | |
| detect-changes: | |
| name: Detect Data Changes | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'pull_request' || github.event_name == 'push' | |
| outputs: | |
| packages: ${{ steps.filter.outputs.changes }} | |
| branch: ${{ github.event.pull_request.head.ref || github.ref_name }} | |
| pr_number: ${{ github.event.pull_request.number }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: dorny/paths-filter@v3 | |
| id: filter | |
| with: | |
| base: ${{ github.event.pull_request.base.ref || github.event.before || 'HEAD~1' }} | |
| filters: | | |
| country/subdivisions: | |
| - 'i18nify-data/country/subdivisions/**' | |
| - '!i18nify-data/country/subdivisions/README.md' | |
| currency: | |
| - 'i18nify-data/currency/**' | |
| - '!i18nify-data/currency/README.md' | |
| bankcodes: | |
| - 'i18nify-data/bankcodes/**' | |
| - '!i18nify-data/bankcodes/README.md' | |
| country/metadata: | |
| - 'i18nify-data/country/metadata/**' | |
| - '!i18nify-data/country/metadata/README.md' | |
| # For workflow_dispatch: get inputs | |
| check-dispatch: | |
| name: Parse Manual Dispatch | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'workflow_dispatch' | |
| outputs: | |
| packages: ${{ steps.parse.outputs.packages }} | |
| branch: ${{ github.event.inputs.branch }} | |
| steps: | |
| - name: Parse inputs | |
| id: parse | |
| env: | |
| PACKAGE: ${{ github.event.inputs.package }} | |
| run: | | |
| if [ "$PACKAGE" != "all" ] && [ -n "$PACKAGE" ]; then | |
| echo "packages=[\"$PACKAGE\"]" >> $GITHUB_OUTPUT | |
| else | |
| echo 'packages=["country/subdivisions","currency","bankcodes","country/metadata"]' >> $GITHUB_OUTPUT | |
| fi | |
| # Generate packages | |
| generate: | |
| name: Generate ${{ matrix.package }} | |
| runs-on: ubuntu-latest | |
| needs: [detect-changes, check-dispatch] | |
| if: | | |
| always() && ( | |
| (needs.detect-changes.result == 'success' && needs.detect-changes.outputs.packages != '[]' && needs.detect-changes.outputs.packages != '') || | |
| (needs.check-dispatch.result == 'success') | |
| ) | |
| strategy: | |
| matrix: | |
| package: ${{ fromJson(needs.check-dispatch.outputs.packages || needs.detect-changes.outputs.packages || '[]') }} | |
| fail-fast: false | |
| env: | |
| BRANCH: ${{ needs.check-dispatch.outputs.branch || needs.detect-changes.outputs.branch }} | |
| PR_NUMBER: ${{ needs.detect-changes.outputs.pr_number || '' }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: ${{ env.BRANCH }} | |
| - name: Check if proto exists | |
| id: check-proto | |
| run: | | |
| PROTO_DIR="i18nify-data/${{ matrix.package }}/proto" | |
| if [ -d "$PROTO_DIR" ] && ls "$PROTO_DIR"/*.proto 1> /dev/null 2>&1; then | |
| echo "has_proto=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_proto=false" >> $GITHUB_OUTPUT | |
| echo "⚠️ No proto found for ${{ matrix.package }} - skipping" | |
| fi | |
| - name: Setup Go | |
| if: steps.check-proto.outputs.has_proto == 'true' | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.20' | |
| - name: Install protoc | |
| if: steps.check-proto.outputs.has_proto == 'true' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y protobuf-compiler jq | |
| go install google.golang.org/protobuf/cmd/[email protected] | |
| echo "$HOME/go/bin" >> $GITHUB_PATH | |
| - name: Generate package | |
| if: steps.check-proto.outputs.has_proto == 'true' | |
| run: | | |
| chmod +x .github/scripts/go/generate-package.sh | |
| .github/scripts/go/generate-package.sh "${{ matrix.package }}" | |
| - name: Commit and push generated package | |
| if: steps.check-proto.outputs.has_proto == 'true' | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add "i18nify-data/go/${{ matrix.package }}" | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "chore: auto-regenerate ${{ matrix.package }} Go package" | |
| git pull --rebase origin "$BRANCH" || true | |
| git push origin HEAD:"$BRANCH" | |
| fi | |
| - name: Generate version and update go.mod | |
| if: steps.check-proto.outputs.has_proto == 'true' | |
| id: version | |
| run: | | |
| COMMIT_SHA=$(git rev-parse HEAD) | |
| SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-12) | |
| TIMESTAMP=$(TZ=UTC git show -s --format=%cd --date=format-local:%Y%m%d%H%M%S "$COMMIT_SHA") | |
| VERSION="v0.0.0-${TIMESTAMP}-${SHORT_SHA}" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| chmod +x .github/scripts/go/update-dependencies.sh | |
| .github/scripts/go/update-dependencies.sh "${{ matrix.package }}" "$VERSION" | |
| - name: Commit and push go.mod | |
| if: steps.check-proto.outputs.has_proto == 'true' | |
| run: | | |
| git add packages/i18nify-go/go.mod packages/i18nify-go/go.sum | |
| if git diff --cached --quiet; then | |
| echo "No go.mod changes" | |
| exit 0 | |
| fi | |
| git commit -m "chore(go): update ${{ matrix.package }} to ${{ steps.version.outputs.version }}" | |
| git pull --rebase origin "$BRANCH" || true | |
| git push origin HEAD:"$BRANCH" | |
| - name: Comment on PR | |
| if: steps.check-proto.outputs.has_proto == 'true' && env.PR_NUMBER != '' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| MODULE="github.com/razorpay/i18nify/i18nify-data/go/${{ matrix.package }}" | |
| gh pr comment "$PR_NUMBER" --body "## 📦 Package Updated | |
| **Package:** \`${{ matrix.package }}\` | |
| **Version:** \`$VERSION\` | |
| \`\`\`bash | |
| go get ${MODULE}@${VERSION} | |
| \`\`\`" |