|
| 1 | +# Create winget pacakge YAML file and open a PR in the repository |
| 2 | +# |
| 3 | +# Required secrets: |
| 4 | +# - WINGET_UPSTREAM_REPO - repository with the YAML files, by default microsoft/winget-pkgs |
| 5 | +# - WINGET_WORKER_NAME - GitHub username of the machine account that will create the PR. The account |
| 6 | +# must have a fork of the upstream repo |
| 7 | +# - WINGET_WORKER_EMAIL - machine account e-mail |
| 8 | +# - WINGET_WORKER_PAT- machine account Personal Access Token |
| 9 | + |
1 | 10 | name: publish-winget |
2 | 11 |
|
3 | 12 | on: |
|
8 | 17 | publish-winget: |
9 | 18 | runs-on: ubuntu-latest |
10 | 19 | steps: |
| 20 | + - run: echo "::set-env name=VERSION::${GITHUB_REF:11}" |
11 | 21 | - name: Test if the package isn't already published |
12 | 22 | run: | |
13 | | - VERSION=${GITHUB_REF:11} |
14 | | - echo Looking for https://raw.githubusercontent.com/microsoft/winget-pkgs/master/manifests/OpenJS/NodeJS/$VERSION.yaml |
15 | | - if curl --output /dev/null --silent --head --fail https://raw.githubusercontent.com/microsoft/winget-pkgs/master/manifests/OpenJS/NodeJS/$VERSION.yaml; then |
| 23 | + echo Looking for https://raw.githubusercontent.com/${{ secrets.WINGET_UPSTREAM_REPO }}/master/manifests/OpenJS/NodeJS/$VERSION.yaml |
| 24 | + if curl --output /dev/null --silent --head --fail https://raw.githubusercontent.com/${{ secrets.WINGET_UPSTREAM_REPO }}/master/manifests/OpenJS/NodeJS/$VERSION.yaml; then |
16 | 25 | echo "Package already exists, exiting" |
17 | 26 | exit 1 |
18 | 27 | fi |
| 28 | + - name: Setup repository |
| 29 | + run: | |
| 30 | + git config --global user.name ${{ secrets.WINGET_WORKER_NAME }} |
| 31 | + git config --global user.email ${{ secrets.WINGET_WORKER_EMAIL }} |
| 32 | + git clone https://github.com/${{ secrets.WINGET_WORKER_NAME }}/winget-pkgs |
| 33 | + cd winget-pkgs |
| 34 | + git remote add upstream https://github.com/${{ secrets.WINGET_UPSTREAM_REPO }} |
| 35 | + git fetch upstream |
| 36 | + git checkout -b add-v$VERSION -t upstream/master |
| 37 | + - run: echo "::set-env name=YAMLFILE::manifests/OpenJS/NodeJS/$VERSION.yaml" |
| 38 | + - name: Create YAML file |
| 39 | + run: | |
| 40 | + cd winget-pkgs |
| 41 | + MSISHA256=`curl --silent https://nodejs.org/dist/v$VERSION/SHASUMS256.txt | grep node-v$VERSION-x64.msi | awk '{print $1;}'` |
| 42 | + echo "Id: OpenJS.Nodejs" > $YAMLFILE |
| 43 | + echo "Version: $VERSION" >> $YAMLFILE |
| 44 | + echo "Name: Node.js" >> $YAMLFILE |
| 45 | + echo "Publisher: OpenJS Foundation" >> $YAMLFILE |
| 46 | + echo "AppMoniker: node" >> $YAMLFILE |
| 47 | + echo "License: Copyright Node.js contributors. All rights reserved." >> $YAMLFILE |
| 48 | + echo "LicenseUrl: https://raw.githubusercontent.com/nodejs/node/master/LICENSE" >> $YAMLFILE |
| 49 | + echo "Homepage: https://nodejs.org/" >> $YAMLFILE |
| 50 | + echo "Description: Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine." >> $YAMLFILE |
| 51 | + echo "InstallerType: msi" >> $YAMLFILE |
| 52 | + echo "Installers:" >> $YAMLFILE |
| 53 | + echo " - Arch: x64" >> $YAMLFILE |
| 54 | + echo " Url: https://nodejs.org/dist/v$VERSION/node-v$VERSION-x64.msi" >> $YAMLFILE |
| 55 | + echo " Sha256: $MSISHA256" >> $YAMLFILE |
| 56 | + cat $YAMLFILE; |
| 57 | + - name: Create commit |
| 58 | + run: | |
| 59 | + cd winget-pkgs |
| 60 | + git add $YAMLFILE; |
| 61 | + git commit -m "Add Node.js $VERSION package"; |
| 62 | + git push https://${{ secrets.WINGET_WORKER_NAME }}:${{ secrets.WINGET_WORKER_PAT }}@github.com/${{ secrets.WINGET_WORKER_NAME }}/winget-pkgs add-v$VERSION |
| 63 | + - name: Open PR |
| 64 | + run: | |
| 65 | + curl --request POST |
| 66 | + --url "https://api.github.com/repos/${{ secrets.WINGET_UPSTREAM_REPO }}/pulls" |
| 67 | + --header "authorization: Bearer ${{ secrets.WINGET_WORKER_PAT }}" |
| 68 | + --header 'content-type: application/json' \ |
| 69 | + --data "{ \ |
| 70 | + \"title\": \"Node.js v$VERSION\", \ |
| 71 | + \"body\": \"Add Node.js installer $VERSION\", \ |
| 72 | + \"head\": \"${{ secrets.WINGET_WORKER_NAME }}:add-v$VERSION\", \ |
| 73 | + \"base\": \"master\" \ |
| 74 | + }" |
0 commit comments