Daily Proto Extraction #393
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: Daily Proto Extraction | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' # Runs daily at midnight UTC | |
| workflow_dispatch: # Allows manual triggering | |
| jobs: | |
| extract-and-commit: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Grant write permission to the repository contents | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Define Variable | |
| run: | | |
| LATEST_LINUX_VERSION=$(git ls-remote --tags https://github.com/torvalds/linux.git | grep -P 'refs/tags/v\d+\.\d+$' | awk '{print$NF}' | awk -F'/' '{print$NF}' | sort -V | tail -1) | |
| echo "latest-linux-version=$LATEST_LINUX_VERSION" >> $GITHUB_ENV | |
| - name: We exit the step if the proto file already exists | |
| run: | | |
| if [ -f "./protos/${{ env.latest-linux-version }}.txt.gz" ]; then | |
| echo "EXTRACT_PROTOS=false" >> $GITHUB_ENV | |
| else | |
| echo "EXTRACT_PROTOS=true" >> $GITHUB_ENV | |
| fi | |
| - name: Clone Kernel | |
| uses: actions/checkout@v4 | |
| if: env.EXTRACT_PROTOS == 'true' | |
| with: | |
| repository: torvalds/linux | |
| ref: ${{ env.latest-linux-version }} | |
| path: ./linux | |
| - name: Extract prototypes for that kernel | |
| if: env.EXTRACT_PROTOS == 'true' | |
| run: | | |
| set -euxo pipefail | |
| # we work in linux directory | |
| pushd linux | |
| version=${{ env.latest-linux-version }} | |
| out=../protos/$version.txt | |
| while read file | |
| do | |
| echo "$version: $file" | |
| file=$(sed -e 's/^\.\///' <<<$file) | |
| ../cprotos.sh $file | sed -e"s#^#$version:$file:#" >> $out | |
| done < <(find -type f -name '*.c' ) | |
| gzip $out | |
| popd | |
| # now update the latest symlink | |
| pushd protos | |
| unlink latest.txt.gz | |
| ln -s "$out.gz" latest.txt.gz | |
| - name: Check for changes in protos directory | |
| id: check-changes | |
| run: | | |
| if [ -n "$(git status --porcelain ./protos/)" ]; then | |
| echo "changes_detected=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "changes_detected=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Commit and push changes | |
| if: steps.check-changes.outputs.changes_detected == 'true' | |
| run: | | |
| set -euxo pipefail | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "actions@github.com" | |
| # Add all files in the protos directory | |
| git add ./protos/ | |
| # Commit changes | |
| git commit -m "update: protos from daily extraction [skip ci]" | |
| # Push changes | |
| git push origin HEAD:${{ github.ref }} |