v4.73.25 #432
This file contains 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: Generate File | |
permissions: | |
actions: write | |
attestations: write | |
checks: write | |
contents: write | |
deployments: write | |
id-token: write | |
issues: read | |
discussions: read | |
packages: read | |
pages: read | |
pull-requests: write | |
repository-projects: read | |
security-events: read | |
statuses: read | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- '**.md' # Ignore markdown files changes to trigger this workflow | |
- '**.gitignore' | |
- 'LICENSE' | |
jobs: | |
generate: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 # Fetch only the last 2 commits to check for changes in version.ini | |
- name: Cache files | |
uses: actions/cache@v3 | |
with: | |
path: | | |
./version.ini | |
./js/content.js | |
./userscript/template.js | |
key: files-key-${{ hashFiles('./version.ini', './js/content.js', './userscript/template.js') }} | |
- name: Read version | |
run: echo "VERSION=$(cat version.ini)" >> $GITHUB_ENV | |
- name: Check if version has changed | |
id: version-check | |
run: | | |
git diff --exit-code --quiet HEAD..HEAD^ version.ini || echo "HAS_CHANGED=true" >> $GITHUB_ENV | |
- name: Create directory | |
run: mkdir -p generated | |
- name: Remove comment and Generate file | |
if: env.HAS_CHANGED == 'true' | |
run: | | |
version="${{ env.VERSION }}" | |
commit_sha=$(git rev-parse HEAD) | |
commit_desc="$(git log -1 --pretty=%B | sed '1d' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" | |
content_r=$(perl -0777 -pe 's|\s*\/\*[^\*]*(?:(?!\*\/)\*[^\*]*)*\*\/\s*||' js/content.js) | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git checkout -B generated-files origin/main | |
echo "$content_r" > temp_content.js | |
cp userscript/template.js temp_template.js | |
sed -i "s/{{VERSION}}/$version/g; s/{{COMMIT_SHA}}/$commit_sha/g" temp_template.js | |
sed -i '/{{CONTENT}}/r temp_content.js' temp_template.js | |
sed -i '/{{CONTENT}}/d' temp_template.js | |
rm temp_content.js | |
mv -f temp_template.js generated/Tabview-Youtube.user.js | |
git add generated/Tabview-Youtube.user.js | |
if ! git diff --exit-code --quiet --cached; then | |
git commit -m "UserJS (v$version) | $commit_sha" -m "$commit_desc" | |
git push -f origin generated-files | |
fi |