Merge pull request #644 from HoangAViet/add-snapvis #1538
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: Parse Submission | |
| on: | |
| push: | |
| branches: | |
| - main | |
| concurrency: | |
| group: parse-submission | |
| cancel-in-progress: false | |
| jobs: | |
| check-commit-message: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| skip: ${{ steps.check.outputs.skip }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| with: | |
| token: ${{ secrets.RBD_GITHUB_TOKEN }} | |
| - name: Check commit message | |
| id: check | |
| run: | | |
| COMMIT_MESSAGE=$(git log -1 --pretty=%B) | |
| if [[ "$COMMIT_MESSAGE" == "Update repository stats" || "$COMMIT_MESSAGE" == "Update app info" ]]; then | |
| echo "skip=true" >> $GITHUB_ENV | |
| echo "::set-output name=skip::true" | |
| else | |
| echo "skip=false" >> $GITHUB_ENV | |
| echo "::set-output name=skip::false" | |
| fi | |
| update-app-info: | |
| if: needs.check-commit-message.outputs.skip == 'false' | |
| runs-on: ubuntu-latest | |
| needs: check-commit-message | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| with: | |
| token: ${{ secrets.RBD_GITHUB_TOKEN }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v2 | |
| with: | |
| node-version: '20' | |
| - name: Install dependencies | |
| run: cd shipixen && npm install | |
| - name: Run update script | |
| run: cd shipixen/scripts && node parse-app-info.js | |
| - name: Commit and push changes | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git add . | |
| git commit -m "Update app info" | |
| git pull --rebase | |
| git push | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.RBD_GITHUB_TOKEN }} | |
| update-stats: | |
| if: needs.check-commit-message.outputs.skip == 'false' | |
| runs-on: ubuntu-latest | |
| needs: update-app-info | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| with: | |
| token: ${{ secrets.RBD_GITHUB_TOKEN }} | |
| - name: Get repository stats | |
| id: get_stats | |
| run: | | |
| REPO_INFO=$(curl -s https://api.github.com/repos/${{ github.repository }}) | |
| STARS=$(echo $REPO_INFO | jq .stargazers_count) | |
| FORKS=$(echo $REPO_INFO | jq .forks_count) | |
| CONTRIBUTORS=$(curl -s https://api.github.com/repos/${{ github.repository }}/contributors\?per_page\=1 -I | grep -i "^link:" | sed -n 's/.*page=\([0-9]*\)>; rel="last".*/\1/p') | |
| if [ -z "$CONTRIBUTORS" ]; then | |
| CONTRIBUTORS=$(curl -s https://api.github.com/repos/${{ github.repository }}/contributors | jq 'length') | |
| fi | |
| echo "stars=$STARS" >> $GITHUB_ENV | |
| echo "forks=$FORKS" >> $GITHUB_ENV | |
| echo "contributors=$CONTRIBUTORS" >> $GITHUB_ENV | |
| - name: Validate and write stats to stats.js | |
| run: | | |
| # Check if any values are null or empty | |
| if [ "${{ env.stars }}" == "null" ] || [ -z "${{ env.stars }}" ] || \ | |
| [ "${{ env.forks }}" == "null" ] || [ -z "${{ env.forks }}" ] || \ | |
| [ "${{ env.contributors }}" == "null" ] || [ -z "${{ env.contributors }}" ]; then | |
| echo "⚠️ Warning: One or more stats values are null or empty. Skipping stats update to preserve existing data." | |
| echo "Stars: ${{ env.stars }}" | |
| echo "Forks: ${{ env.forks }}" | |
| echo "Contributors: ${{ env.contributors }}" | |
| echo "skip_commit=true" >> $GITHUB_ENV | |
| else | |
| echo "✅ All stats are valid. Updating stats.js" | |
| echo "Stars: ${{ env.stars }}" | |
| echo "Forks: ${{ env.forks }}" | |
| echo "Contributors: ${{ env.contributors }}" | |
| echo "module.exports = { stars: ${{ env.stars }}, forks: ${{ env.forks }}, contributors: ${{ env.contributors }} };" > shipixen/data/stats.js | |
| echo "skip_commit=false" >> $GITHUB_ENV | |
| fi | |
| - name: Commit changes | |
| if: env.skip_commit != 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.RBD_GITHUB_TOKEN }} | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git add shipixen/data/stats.js | |
| git commit -m 'Update repository stats' | |
| git pull --rebase | |
| git push https://x-access-token:${{ secrets.RBD_GITHUB_TOKEN }}@github.com/${{ github.repository }}.git |