|
| 1 | +name: Publish |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published, edited] |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + name: Build |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + tag: ${{ steps.update-package-version.outputs.version }} |
| 13 | + steps: |
| 14 | + # Configure runner with the right stuff |
| 15 | + - uses: actions/checkout@v2 |
| 16 | + with: |
| 17 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 18 | + - name: Configure git |
| 19 | + run: | |
| 20 | + git config user.name 'Release Action' |
| 21 | + git config user.email '<>' |
| 22 | + - uses: actions/setup-node@v1 |
| 23 | + with: |
| 24 | + node-version: "12" |
| 25 | + |
| 26 | + # Call `npm version`. It increments the version and commits the changes. |
| 27 | + # We'll save the output (new version string) for use in the following |
| 28 | + # steps |
| 29 | + - name: Update package version |
| 30 | + id: update-package-version |
| 31 | + run: | |
| 32 | + git tag -d "${{ github.event.release.tag_name }}" |
| 33 | + VERSION=$(npm version "${{ github.event.release.tag_name }}" --no-git-tag-version) |
| 34 | + echo "::set-output name=version::$VERSION" |
| 35 | + git add package.json package-lock.json |
| 36 | + git commit -m "[skip ci] Bump $VERSION" |
| 37 | + git push origin HEAD:main |
| 38 | + |
| 39 | + # Now carry on, business as usual |
| 40 | + - name: Perform npm tasks |
| 41 | + run: npm run ci |
| 42 | + |
| 43 | + # Finally, create a detached commit containing the built artifacts and tag |
| 44 | + # it with the release. Note: the fact that the branch is locally updated |
| 45 | + # will not be relayed (pushed) to origin |
| 46 | + - name: Commit to release branch |
| 47 | + id: release_info |
| 48 | + run: | |
| 49 | + # Check for semantic versioning |
| 50 | + echo "Preparing release for version $longVersion" |
| 51 | + longVersion="${{github.event.release.tag_name}}" |
| 52 | + [[ $longVersion == v[0-9]*.[0-9]*.[0-9]* ]] || (echo "must follow semantic versioning" && exit 1) |
| 53 | + majorVersion=$(echo ${longVersion%.*.*}) |
| 54 | + minorVersion=$(echo ${longVersion%.*}) |
| 55 | +
|
| 56 | + # Add the built artifacts. Using --force because dist/lib should be in |
| 57 | + # .gitignore |
| 58 | + git add --force dist lib |
| 59 | +
|
| 60 | + # Make the commit |
| 61 | + MESSAGE="Build for $(git rev-parse --short HEAD)" |
| 62 | + git commit --allow-empty -m "$MESSAGE" |
| 63 | + git tag -f -a -m "Release $longVersion" $longVersion |
| 64 | +
|
| 65 | + # Get the commit of the tag you just released |
| 66 | + commitHash=$(git rev-list -n 1 $longVersion) |
| 67 | + |
| 68 | + # Delete the old major and minor version tags locally |
| 69 | + git tag -d $majorVersion || true |
| 70 | + git tag -d $minorVersion || true |
| 71 | + |
| 72 | + # Make new major and minor version tags locally that point to the commit you got from the "git rev-list" above |
| 73 | + git tag -f $majorVersion $commitHash |
| 74 | + git tag -f $minorVersion $commitHash |
| 75 | + |
| 76 | + # Force push the new minor version tag to overwrite the old tag remotely |
| 77 | + echo "Pushing new tags" |
| 78 | + git push -f origin $longVersion |
| 79 | + git push -f origin $majorVersion |
| 80 | + git push -f origin $minorVersion |
0 commit comments