From d55a5fec7cbcea3a00644568c4b3d7fb6b45d1f1 Mon Sep 17 00:00:00 2001 From: Rakshith B <79500257+Rakshithb1@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:47:25 +0530 Subject: [PATCH] [MOSIP-36481] added xlsx-to-csv.yml Signed-off-by: Rakshith B <79500257+Rakshithb1@users.noreply.github.com> --- .github/workflows/xlsx-to-csv.yml | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/xlsx-to-csv.yml diff --git a/.github/workflows/xlsx-to-csv.yml b/.github/workflows/xlsx-to-csv.yml new file mode 100644 index 00000000..fd26b001 --- /dev/null +++ b/.github/workflows/xlsx-to-csv.yml @@ -0,0 +1,59 @@ +name: xlsx to csv conversion + +on: + pull_request_target: + types: [opened, reopened, synchronize] + workflow_dispatch: + inputs: + message: + description: 'Message for manually triggering' + required: false + default: 'Triggered for Updates' + type: string + +jobs: + convert_xlsx_to_csv: + runs-on: ubuntu-latest + steps: + - name: Clone the repository + 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 + 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 + run: | + git config --global user.name "${{ github.event.pull_request.user.login }}" + git config --global user.email "${{ env.author_email }}" + + - name: Install xlsx2csv + run: sudo apt-get install -y xlsx2csv + + - name: Create output directory + run: | + rm -rf mosip-data/mosip_master_csv/csv + mkdir -p mosip-data/mosip_master_csv/csv + + - name: Convert all XLSX to CSV + 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")" + xlsx2csv "$xlsx_file" > "$csv_file" + echo "Converted $xlsx_file to $csv_file" + done + + - name: Commit and push changes + run: | + cd mosip-data + git branch + git add . + git commit -s -m "Added converted CSV files" || echo "No changes to commit" + git push "https://x-access-token:${{ secrets.ACTION_PAT }}@github.com/${{ github.event.pull_request.head.repo.full_name }}.git" HEAD:${{ github.event.pull_request.head.ref }}