Jelajahi Sumber

Update GitHub Actions workflows

Lutz Roeder 10 bulan lalu
induk
melakukan
8e8007eb05
2 mengubah file dengan 9 tambahan dan 8 penghapusan
  1. 4 3
      .github/workflows/publish.yml
  2. 5 5
      package.js

+ 4 - 3
.github/workflows/publish.yml

@@ -19,8 +19,8 @@ jobs:
 
       - name: Git credentials
         run: |
-          git config --global user.name ${{ secrets.PUBLISH_USER_NAME }}
-          git config --global user.email ${{ secrets.PUBLISH_USER_EMAIL }}
+          git config --global user.name ${{ secrets.PUBLISH_GITHUB_USER_NAME }}
+          git config --global user.email ${{ secrets.PUBLISH_GITHUB_USER_EMAIL }}
 
       - name: Install Node.js
         uses: actions/setup-node@v4
@@ -94,6 +94,7 @@ jobs:
       - if: startsWith(matrix.os, 'windows')
         name: Publish winget
         env:
-          GITHUB_TOKEN: ${{ secrets.PUBLISH_GITHUB_TOKEN }}
           GITHUB_USER: ${{ secrets.PUBLISH_GITHUB_USER }}
+          GITHUB_TOKEN: ${{ secrets.PUBLISH_GITHUB_TOKEN }}
+          WINGET_TOKEN: ${{ secrets.WINGET_TOKEN }}
         run: npm run publish winget

+ 5 - 5
package.js

@@ -126,7 +126,7 @@ const sleep = (delay) => {
 const request = async (url, init, status) => {
     const response = await fetch(url, init);
     if (status !== false && !response.ok) {
-        throw new Error(response.status.toString());
+        throw new Error(`${response.status.toString()} ${response.statusText}`);
     }
     if (response.body) {
         const reader = response.body.getReader();
@@ -196,12 +196,12 @@ const fork = async (organization, repository) => {
     await exec(`git clone --depth=2 https://x-access-token:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_USER}/${repository}.git dist/${repository}`);
 };
 
-const pullrequest = async (organization, repository, body) => {
+const pullrequest = async (organization, repository, token, body) => {
     writeLine(`github push ${repository}`);
     await exec(`git -C dist/${repository} push`);
     writeLine(`github pullrequest ${repository}`);
     const headers = {
-        Authorization: `Bearer ${process.env.GITHUB_TOKEN}`
+        Authorization: `Bearer ${token}`
     };
     await request(`https://api.github.com/repos/${organization}/${repository}/pulls`, {
         method: 'POST',
@@ -399,7 +399,7 @@ const publish = async (target) => {
             writeLine('git push homebrew-cask');
             await exec('git -C dist/homebrew-cask add --all');
             await exec(`git -C dist/homebrew-cask commit -m "${configuration.name} ${configuration.version}"`);
-            await pullrequest('Homebrew', 'homebrew-cask', {
+            await pullrequest('Homebrew', 'homebrew-cask', process.env.GITHUB_TOKEN, {
                 title: `${configuration.name} ${configuration.version}`,
                 body: 'Update version and sha256',
                 head: `${process.env.GITHUB_USER}:master`,
@@ -498,7 +498,7 @@ const publish = async (target) => {
             writeLine('git push winget-pkgs');
             await exec('git -C dist/winget-pkgs add --all');
             await exec(`git -C dist/winget-pkgs commit -m "Update ${configuration.name} to ${configuration.version}"`);
-            await pullrequest('microsoft', 'winget-pkgs', {
+            await pullrequest('microsoft', 'winget-pkgs', process.env.WINGET_TOKEN, {
                 title: `Update ${configuration.productName} to ${configuration.version}`,
                 body: '',
                 head: `${process.env.GITHUB_USER}:master`,