Skip to content

Update NLP Engine Files #77

Update NLP Engine Files

Update NLP Engine Files #77

name: Update NLP Engine Files
on:
workflow_dispatch:
repository_dispatch:
types: [nlp-engine-release]
jobs:
update-files:
runs-on: ubuntu-latest
steps:
- name: Checkout this repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history to properly check tags
- name: Get latest release info from VisualText/nlp-engine
id: get_release
uses: actions/github-script@v6
with:
script: |
try {
// Get tag from input or latest release
let tagName = null;
if (context.payload.inputs && context.payload.inputs.tag_name) {
tagName = context.payload.inputs.tag_name;
console.log(`Using provided tag: ${tagName}`);
} else {
const latestRelease = await github.rest.repos.getLatestRelease({
owner: 'VisualText',
repo: 'nlp-engine'
});
tagName = latestRelease.data.tag_name;
console.log(`Using latest release tag: ${tagName}`);
}
core.setOutput('tag_name', tagName);
// Get release by tag
const releaseByTag = await github.rest.repos.getReleaseByTag({
owner: 'VisualText',
repo: 'nlp-engine',
tag: tagName
});
// Log all assets to help debugging
console.log("Available assets in the release:");
releaseByTag.data.assets.forEach(asset => {
console.log(`- ${asset.name} (${asset.browser_download_url})`);
});
// Safe find function that doesn't throw on undefined
const safeFindAsset = (pattern) => {
const asset = releaseByTag.data.assets.find(asset =>
asset.name.includes(pattern) || asset.name.endsWith(pattern)
);
if (!asset) {
console.log(`WARNING: Could not find asset matching pattern: ${pattern}`);
return { browser_download_url: null };
}
return asset;
};
// Get Linux specific assets
const zip = safeFindAsset('nlpengine.zip');
core.setOutput('zip', zip.browser_download_url);
const icu1 = safeFindAsset('libicutu.a');
core.setOutput('icu1', icu1.browser_download_url);
const icu2 = safeFindAsset('libicuuc.a');
core.setOutput('icu2', icu2.browser_download_url);
const nlp = safeFindAsset('nlpl.exe');
core.setOutput('nlp', nlp.browser_download_url);
} catch (error) {
console.log('Error occurred:');
console.log(error);
core.setFailed(`Error fetching release data: ${error.message}`);
}
- name: Show latest release version
run: echo "Latest release version is ${{ steps.get_release.outputs.tag_name }}"
- name: Check if update is needed
id: check_tag
run: |
# Print event name for debugging
echo "Current event name: ${{ github.event_name }}"
# Always update if workflow_dispatch was manually triggered
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "Workflow manually triggered, forcing update"
echo "update_needed=true" >> $GITHUB_OUTPUT
elif git tag -l "${{ steps.get_release.outputs.tag_name }}" | grep -q .; then
echo "Tag ${{ steps.get_release.outputs.tag_name }} already exists in this repo"
echo "update_needed=false" >> $GITHUB_OUTPUT
else
echo "Tag ${{ steps.get_release.outputs.tag_name }} does not exist, update needed"
echo "update_needed=true" >> $GITHUB_OUTPUT
fi
# Show all existing tags for debugging
echo "Existing tags:"
git tag -l
# Print the decision for clarity
echo "DECISION: update_needed=${{ steps.check_tag.outputs.update_needed || 'true' }}"
- name: Download release assets to release-assets directory
if: steps.check_tag.outputs.update_needed == 'true'
run: |
mkdir -p release-assets
wget "${{ steps.get_release.outputs.zip }}" -P release-assets
wget "${{ steps.get_release.outputs.icu1 }}" -P release-assets
wget "${{ steps.get_release.outputs.icu2 }}" -P release-assets
wget "${{ steps.get_release.outputs.nlp }}" -P release-assets
shell: bash
- name: rename nlpl.exe to nlp.exe
if: steps.check_tag.outputs.update_needed == 'true'
run: mv release-assets/nlpl.exe release-assets/nlp.exe
- name: Unzip the nlpengine.zip
if: steps.check_tag.outputs.update_needed == 'true'
run: |
unzip -o release-assets/nlpengine.zip -d release-assets
rm -rf release-assets/nlpengine.zip
- name: Debug before copy
if: steps.check_tag.outputs.update_needed == 'true'
run: |
echo "Current files in repository:"
ls -la
# Check if original files exist and get their checksums
echo "Original file checksums (if they exist):"
if [ -f "nlp.exe" ]; then
echo "Original nlp.exe exists, size: $(stat -c%s nlp.exe)"
md5sum nlp.exe
else
echo "Original nlp.exe does not exist"
fi
if [ -f "libicutu.a" ]; then
echo "Original libicutu.a exists, size: $(stat -c%s libicutu.a)"
md5sum libicutu.a
else
echo "Original libicutu.a does not exist"
fi
if [ -f "libicuuc.a" ]; then
echo "Original libicuuc.a exists, size: $(stat -c%s libicuuc.a)"
md5sum libicuuc.a
else
echo "Original libicuuc.a does not exist"
fi
# Check files in release-assets directory
echo "Downloaded file checksums:"
md5sum release-assets/nlp.exe
md5sum release-assets/libicutu.a
md5sum release-assets/libicuuc.a
# New step: Force remove binary files using git rm
- name: Force remove all binary files
if: steps.check_tag.outputs.update_needed == 'true'
run: |
# Configure git for commits
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# Force remove binary files
echo "Removing binary files using git rm to ensure they're properly tracked..."
git rm -f *.a nlp.exe || true
git rm -f .version-flag || true
# Commit the removal
git commit -m "Remove binary files before update to ${{ steps.get_release.outputs.tag_name }}" || echo "Nothing to commit - files may not exist yet"
git push || echo "Nothing to push"
# Verify files were removed
echo "Current files after removal:"
ls -la
- name: Copy assets to repository overwriting existing files
if: steps.check_tag.outputs.update_needed == 'true'
run: |
# First completely remove old files to avoid comparison issues
rm -rf *.a
rm -rf nlp.exe
rm -rf data
# Copy new files
cp -r release-assets/* .
rm -rf release-assets
# Verify files were copied
echo "After copying, verifying files exist:"
if [ -f "nlp.exe" ]; then
echo "New nlp.exe exists, size: $(stat -c%s nlp.exe)"
else
echo "ERROR: nlp.exe was not copied!"
fi
if [ -f "libicutu.a" ]; then
echo "New libicutu.a exists, size: $(stat -c%s libicutu.a)"
else
echo "ERROR: libicutu.a was not copied!"
fi
if [ -f "libicuuc.a" ]; then
echo "New libicuuc.a exists, size: $(stat -c%s libicuuc.a)"
else
echo "ERROR: libicuuc.a was not copied!"
fi
- name: Debug after copy
if: steps.check_tag.outputs.update_needed == 'true'
run: |
echo "Files after copying:"
ls -la
echo "Git status:"
git status
- name: Configure Git
if: steps.check_tag.outputs.update_needed == 'true'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# Force git to see all files as changed
echo "Setting git config to force detects changes in binary files"
git config --global core.fileMode true
- name: Add and check for changes
if: steps.check_tag.outputs.update_needed == 'true'
id: check_changes
run: |
# List all files for debugging
echo "Current files in repository (after copy):"
ls -la
# Create a version flag file to force change detection
date > .version-flag
echo "${{ steps.get_release.outputs.tag_name }}" >> .version-flag
# Add all changes to staging
git add -A
# Show git status for debugging
echo "Git status after git add -A:"
git status
# Check for staged changes
if git diff --staged --quiet; then
echo "No changes detected in files"
echo "has_changes=false" >> $GITHUB_OUTPUT
# Extra debugging for binary files
echo "Comparing binary files manually:"
if [ -f "nlp.exe" ]; then
echo "nlp.exe exists, size: $(stat -c%s nlp.exe)"
md5sum nlp.exe
fi
if [ -f "libicutu.a" ]; then
echo "libicutu.a exists, size: $(stat -c%s libicutu.a)"
md5sum libicutu.a
fi
if [ -f "libicuuc.a" ]; then
echo "libicuuc.a exists, size: $(stat -c%s libicuuc.a)"
md5sum libicuuc.a
fi
else
echo "Changes detected in files"
git diff --staged --name-status
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
# Print the decision for clarity
echo "DECISION: has_changes=${{ steps.check_changes.outputs.has_changes || 'false' }}"
# Force has_changes to true when workflow_dispatch
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "Workflow manually triggered, forcing has_changes=true"
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Force update tag if it exists
if: steps.check_tag.outputs.update_needed == 'true' && (steps.check_changes.outputs.has_changes == 'true' || github.event_name == 'workflow_dispatch')
run: |
if git tag -l "${{ steps.get_release.outputs.tag_name }}" | grep -q .; then
echo "Removing existing tag ${{ steps.get_release.outputs.tag_name }}"
git tag -d ${{ steps.get_release.outputs.tag_name }}
git push origin :refs/tags/${{ steps.get_release.outputs.tag_name }} || true
fi
- name: Commit and push changes
if: steps.check_tag.outputs.update_needed == 'true' && (steps.check_changes.outputs.has_changes == 'true' || github.event_name == 'workflow_dispatch')
run: |
git commit -m "Update NLP Engine files to latest release ${{ steps.get_release.outputs.tag_name }}"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Tag this repository with the latest release version
if: steps.check_tag.outputs.update_needed == 'true' && (steps.check_changes.outputs.has_changes == 'true' || github.event_name == 'workflow_dispatch')
run: |
git tag ${{ steps.get_release.outputs.tag_name }}
git push origin ${{ steps.get_release.outputs.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create a release for this repository
if: steps.check_tag.outputs.update_needed == 'true' && (steps.check_changes.outputs.has_changes == 'true' || github.event_name == 'workflow_dispatch')
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_release.outputs.tag_name }}
name: Release ${{ steps.get_release.outputs.tag_name }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Report no changes
if: steps.check_tag.outputs.update_needed == 'true' && steps.check_changes.outputs.has_changes != 'true' && github.event_name != 'workflow_dispatch'
run: |
echo "No changes were detected. Repository already has the latest files from release ${{ steps.get_release.outputs.tag_name }}"
- name: Report no update needed
if: steps.check_tag.outputs.update_needed != 'true' && github.event_name != 'workflow_dispatch'
run: |
echo "No update needed. Repository is already at version ${{ steps.get_release.outputs.tag_name }}"