From d14ba069cd07ee625a0e58a462bf3d088c5fe4c4 Mon Sep 17 00:00:00 2001 From: Philipp Kief Date: Wed, 15 Nov 2023 07:05:12 +0100 Subject: [PATCH] Update workflows (#2147) * Add workflow file * Update workflow file * Add delete workflow * Update workflow files * Update workflow files --- .github/workflows/build.yml | 7 +++- .github/workflows/color-check.yml | 3 +- .github/workflows/icon-review.yml | 61 +++++++++++++++++++++++++++++++ .github/workflows/pr-closed.yml | 59 ++++++++++++++++++++++++++++++ .github/workflows/release.yml | 12 +++++- 5 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/icon-review.yml create mode 100644 .github/workflows/pr-closed.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 85d57d2ac5..c1114e219e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,17 +14,21 @@ jobs: steps: - name: Checkout 🛎 - uses: actions/checkout@v3 + uses: actions/checkout@v4 + - name: Setup Node.js ${{ matrix.node-version }} ⚙ uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} + - name: Run display server 🖥 run: /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & echo "Started xvfb" shell: bash if: ${{ success() && matrix.os == 'ubuntu-latest' }} + - name: Install node_modules 📦 run: npm ci + - name: Cache node_modules 💾 uses: actions/cache@v3 env: @@ -37,6 +41,7 @@ jobs: ${{ runner.os }}-build-${{ env.cache-name }}- ${{ runner.os }}-build- ${{ runner.os }}- + - name: Test + Build 🚀 run: | npm test diff --git a/.github/workflows/color-check.yml b/.github/workflows/color-check.yml index 27e4d9db7d..5c33bb7c24 100644 --- a/.github/workflows/color-check.yml +++ b/.github/workflows/color-check.yml @@ -13,9 +13,10 @@ jobs: TARGET_BRANCH: ${{ github.event.pull_request.base.ref }} steps: - name: Checkout 🛎️ - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Check colors 🎨 run: | svgFiles=$(git diff origin/${{ env.TARGET_BRANCH }} --diff-filter=ACMRTUX --name-only | grep '.svg$') diff --git a/.github/workflows/icon-review.yml b/.github/workflows/icon-review.yml new file mode 100644 index 0000000000..782eae9228 --- /dev/null +++ b/.github/workflows/icon-review.yml @@ -0,0 +1,61 @@ +name: Icon Review + +on: + pull_request: + paths: + - 'icons/*.svg' + +jobs: + icon-review: + name: Icon Review + runs-on: ubuntu-latest + env: + TARGET_BRANCH: ${{ github.event.pull_request.base.ref }} + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Review SVG files 🔍 + run: | + svgFiles=$(git diff origin/${{ env.TARGET_BRANCH }} --diff-filter=ACMRTUX --name-only | grep '.svg$') + echo "SVG files changed: ${svgFiles}" + npx svg-icon-review ${svgFiles} + + - name: Upload PNG to Repository ⬆️ + run: | + mkdir -p review-images + mv ./preview.png review-images/${{ github.event.pull_request.number }}_${{ github.sha }}.png + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git fetch origin + git checkout -b review-images origin/review-images --no-track + git add review-images/ + git commit -m "Add generated review image" + git push -u origin review-images + + - name: Post review in PR ✍️ + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const pngFilePath = './preview.png'; + const commentBody = ` + ## Preview + + Thank you for creating a pull request. This preview shows you how your changes will look on the different themes: + + ![Generated Preview](https://raw.githubusercontent.com/' + context.repo.owner + '/' + context.repo.repo + '/' + 'review-images/review-images/${{ github.event.pull_request.number }}_${{ github.sha }}.png) + + You can find more information how to contribute in the [contribution guidelines](https://github.com/PKief/vscode-material-icon-theme/blob/main/CONTRIBUTING.md). + `; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody + }) + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pr-closed.yml b/.github/workflows/pr-closed.yml new file mode 100644 index 0000000000..6e78e77a12 --- /dev/null +++ b/.github/workflows/pr-closed.yml @@ -0,0 +1,59 @@ +name: PR closed + +on: + pull_request: + types: + - closed + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Checkout review-images branch 🛎️ + uses: actions/checkout@v4 + with: + ref: review-images + + - name: Delete PR related files 🗑️ + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const path = require('path'); + const dir = './review-images'; + const prNumber = context.payload.pull_request.number; + + fs.readdirSync(dir).forEach(file => { + if (file.startsWith(`${prNumber}_`)) { + fs.unlinkSync(path.join(dir, file)); + } + }); + + - name: Commit changes ⬆️ + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add -A + if [[ $(git diff --stat --staged) != '' ]]; then + git commit -m "Delete files related to PR #${{ github.event.pull_request.number }}" + git push + fi + + thank_you: + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true + steps: + - name: Post Thank You Comment 🙏 + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `## Merge Successful + + Thanks for your contribution! 🎉 + + The changes will be part of the upcoming update on the marketplace.` + }) \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d54b483484..da69e3af14 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,24 +19,28 @@ jobs: VERSION_CHANGE: ${{ github.event.inputs.versionChange }} steps: - name: Checkout 🛎️ - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Setup Node.js ⚙️ uses: actions/setup-node@v3 with: node-version: 'lts/*' registry-url: 'https://registry.npmjs.org' + - name: Install node_modules 📦 run: | npm ci npm install --global @vscode/vsce + - name: Update version ↗ run: | git config --global user.name 'Philipp Kief' git config --global user.email 'PKief@users.noreply.github.com' git config --global push.followTags true npm version ${{ env.VERSION_CHANGE }} -m "Release %s" + - name: Get meta data 🔍 run: | NODE_VERSION=$(node -p -e "require('./package.json').version") @@ -45,10 +49,13 @@ jobs: echo NAME=$NODE_NAME >> $GITHUB_ENV NODE_DISPLAY_NAME=$(node -p -e "require('./package.json').displayName") echo DISPLAY_NAME=$NODE_DISPLAY_NAME >> $GITHUB_ENV + - name: Build ⚒️ run: vsce package + - name: Push tags 📌 run: git push + - name: Release ${{ env.VERSION }} 🔆 uses: softprops/action-gh-release@v1 with: @@ -56,17 +63,20 @@ jobs: tag_name: v${{ env.VERSION }} name: ${{ env.DISPLAY_NAME }} v${{ env.VERSION }} generate_release_notes: true + - name: Publish to Open VSX Registry 🌐 uses: HaaLeo/publish-vscode-extension@v1 with: pat: ${{ secrets.OPEN_VSX_TOKEN }} extensionFile: ${{ env.NAME }}-${{ env.VERSION }}.vsix + - name: Publish to Visual Studio Marketplace 🌐 uses: HaaLeo/publish-vscode-extension@v1 with: pat: ${{ secrets.VS_MARKETPLACE_TOKEN }} registryUrl: https://marketplace.visualstudio.com extensionFile: ${{ env.NAME }}-${{ env.VERSION }}.vsix + - name: Publish to NPM Registry 🌐 run: npm publish env: