Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions .github/workflows/xlsx-to-csv.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: xlsx to csv conversion

on:
pull_request_target:
types: [opened, reopened, synchronize]
Expand All @@ -15,34 +14,55 @@ jobs:
convert_xlsx_to_csv:
runs-on: ubuntu-latest
steps:
- name: Check for xlsx changes
id: check_xlsx
run: |
PR_NUMBER=${{ github.event.number }}
FILES=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER/files")
Comment thread
abhishek8shankar marked this conversation as resolved.
XLSX_CHANGED=$(echo "$FILES" | jq '[.[].filename | select(endswith(".xlsx"))] | length')
Comment thread
abhishek8shankar marked this conversation as resolved.
echo "xlsx_changed=$XLSX_CHANGED" >> $GITHUB_OUTPUT
Comment thread
abhishek8shankar marked this conversation as resolved.

- name: Skip if no xlsx changes
if: steps.check_xlsx.outputs.xlsx_changed == '0' && github.event_name != 'workflow_dispatch'
run: |
echo "No xlsx files changed. Skipping workflow."
exit 0

- name: Clone the repository
if: steps.check_xlsx.outputs.xlsx_changed != '0' || github.event_name == 'workflow_dispatch'
run: |
#git clone -b ${{ github.event.pull_request.head.ref }} "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.event.pull_request.head.repo.full_name }}.git"
git clone -b ${{ github.event.pull_request.head.ref }} https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git

- name: Get author email

- name: Get author email
if: steps.check_xlsx.outputs.xlsx_changed != '0' || github.event_name == 'workflow_dispatch'
run: |
PR_NUMBER=${{ github.event.number }}
commits=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER/commits")
email=$(echo "$commits" | jq -r '.[0].commit.author.email // "${{ github.event.pull_request.user.login }}@users.noreply.github.com"')
echo "author_email=$email" >> $GITHUB_ENV

- name: Set up Git identity
if: steps.check_xlsx.outputs.xlsx_changed != '0' || github.event_name == 'workflow_dispatch'
run: |
git config --global user.name "${{ github.event.pull_request.user.login }}"
git config --global user.email "${{ env.author_email }}"

- name: Install xlsx2csv
if: steps.check_xlsx.outputs.xlsx_changed != '0' || github.event_name == 'workflow_dispatch'
run: sudo apt-get install -y xlsx2csv

- name: Create output directory
if: steps.check_xlsx.outputs.xlsx_changed != '0' || github.event_name == 'workflow_dispatch'
run: |
rm -rf mosip-data/mosip_master_csv/csv
mkdir -p mosip-data/mosip_master_csv/csv

- name: Convert all XLSX to CSV
if: steps.check_xlsx.outputs.xlsx_changed != '0' || github.event_name == 'workflow_dispatch'
run: |
for xlsx_file in mosip-data/mosip_master/xlsx/*.xlsx; do
csv_file="mosip-data/mosip_master_csv/csv/$(basename "${xlsx_file%.xlsx}.csv")"
Expand All @@ -51,6 +71,7 @@ jobs:
done

- name: Commit and push changes
if: steps.check_xlsx.outputs.xlsx_changed != '0' || github.event_name == 'workflow_dispatch'
run: |
cd mosip-data
git branch
Expand Down
Loading