├── Dockerfile ├── README.md ├── action.yml └── main.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.9 2 | 3 | RUN apk update && apk add bash git npm jq 4 | 5 | COPY main.sh /main.sh 6 | 7 | RUN chmod +x /main.sh 8 | 9 | ENTRYPOINT ["/main.sh"] 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Action for publish UPM 2 | 3 | ## Features 4 | 5 | * Publish Unity Packages to UPM registry 6 | * Automatic edit `package.json` and `CHANGELOG.md` 7 | 8 | ## Prepare 9 | 10 | ### 1. Setup Secrets in Repository Settings 11 | 12 | 1. Open Secrets settings
![image](https://user-images.githubusercontent.com/838945/74607506-af49b980-511c-11ea-9081-e8b23e695068.png) 13 | 1. Add new secrets: Name: `NPM_AUTH_TOKEN`, Value: Your auth token of UPM Registry
![image](https://user-images.githubusercontent.com/838945/74607552-1cf5e580-511d-11ea-8407-941511298909.png) 14 | 1. Add new secrets: Name: `NPM_REGISTRY_URL`, Value: Your UPM Registry URL.
![image](https://user-images.githubusercontent.com/838945/84682501-ad7bef80-af70-11ea-9868-4b53a497be3d.png) 15 | 16 | ### 2. Setup GitHub Actions Workflow 17 | 18 | Setup GitHub Actions Workflow as below example. 19 | 20 | ```yaml 21 | name: Publish UPM Package 22 | 23 | on: 24 | release: 25 | types: [published] 26 | 27 | jobs: 28 | upm-publish: 29 | 30 | runs-on: ubuntu-latest 31 | 32 | steps: 33 | - uses: actions/checkout@v2 34 | - uses: monry/actions-upm-publish@v1 35 | with: 36 | npm_registry_url: ${{ secrets.NPM_REGISTRY_URL }} 37 | npm_auth_token: ${{ secrets.NPM_AUTH_TOKEN }} 38 | ``` 39 | 40 | You can specify directory path of `package.json` by set path into `package_directory_path` (default: `Assets`) 41 | 42 | ### Note: Registry URL 43 | 44 | You can also specify registry URL using `.npmrc` instead of specifying in actions workflow. 45 | 46 | ```.npmrc 47 | registry=[UPM Registry URL] 48 | ``` 49 | 50 | ## Usages 51 | 52 | When you create a new release on GitHub, Actions are executed to do the following: 53 | 54 | * Update `version` field in `Assets/package.json` 55 | * Add release notes into `Assets/CHANGELOG.md` 56 | * Commit and Push to registry and replace hash of release tag -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Publish UPM' 2 | description: 'Publish Unity package to UPM Registry' 3 | author: 'Tetsuya Mori' 4 | branding: 5 | icon: 'box' 6 | color: 'white' 7 | inputs: 8 | release_summary: 9 | description: 'Summary of Release' 10 | required: true 11 | default: ${{ github.event.release.name }} 12 | release_body: 13 | description: 'Body of Release' 14 | required: true 15 | default: ${{ github.event.release.body }} 16 | release_version: 17 | description: 'Version of Release' 18 | required: true 19 | default: ${{ github.event.release.tag_name }} 20 | release_branch: 21 | description: 'Branch name of Release' 22 | required: true 23 | default: ${{ github.event.release.target_commitish }} 24 | github_actor: 25 | description: 'GitHub actor name' 26 | required: true 27 | default: ${{ github.actor }} 28 | github_repository: 29 | description: 'GitHub Repository name' 30 | required: true 31 | default: ${{ github.repository }} 32 | github_token: 33 | description: 'GitHub auth token' 34 | required: true 35 | package_directory_path: 36 | description: 'Directory path of package.json' 37 | required: true 38 | default: 'Assets' 39 | npm_registry_url: 40 | description: 'URL of UPM Registry' 41 | required: true 42 | npm_auth_token: 43 | description: 'Auth token for UPM Registry' 44 | required: true 45 | runs: 46 | using: 'Docker' 47 | image: 'Dockerfile' -------------------------------------------------------------------------------- /main.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | cat << EOS | sed -i '1r /dev/stdin' Assets/CHANGELOG.md 6 | 7 | ## [${INPUT_RELEASE_VERSION##v}] - $(date "+%Y-%m-%d") 8 | 9 | ${INPUT_RELEASE_SUMMARY} 10 | 11 | $(echo "${INPUT_RELEASE_BODY}" | sed 's/^#/\#\#/') 12 | EOS 13 | cat Assets/package.json | jq -Mr '. | .version = "'"${INPUT_RELEASE_VERSION##v}"'"' > /tmp/package.json 14 | mv /tmp/package.json Assets/package.json 15 | 16 | if [ -z "${INPUT_NPM_REGISTRY_URL}" ]; then 17 | INPUT_NPM_REGISTRY_URL=$(cat .npmrc | sed 's/^registry=//') 18 | echo $(cat .npmrc | grep '^registry=' | sed 's/^registry=https://')'/:_authToken="'${INPUT_NPM_AUTH_TOKEN}'"' >> ~/.npmrc 19 | else 20 | echo $(echo -n "${INPUT_NPM_REGISTRY_URL}" | sed 's/^https://')'/:_authToken="'${INPUT_NPM_AUTH_TOKEN}'"' >> ~/.npmrc 21 | fi 22 | npm publish --tag latest --registry ${INPUT_NPM_REGISTRY_URL} ${INPUT_PACKAGE_DIRECTORY_PATH} 23 | 24 | git config --global user.email "github-actions@example.com" 25 | git config --global user.name "GitHub Actions" 26 | git checkout -b "temporary-$(date '+%Y%m%d%H%M%S')" 27 | git add . 28 | git commit -m ":up: Bump up version: ${INPUT_RELEASE_VERSION}" && git push "https://${INPUT_GITHUB_ACTOR}}:${INPUT_GITHUB_TOKEN}@github.com/${INPUT_GITHUB_REPOSITORY}.git" HEAD:${INPUT_RELEASE_BRANCH} || true 29 | git tag -d ${INPUT_RELEASE_VERSION} 30 | git tag ${INPUT_RELEASE_VERSION} 31 | git push --tags --force 32 | --------------------------------------------------------------------------------