|
| 1 | +# test |
| 2 | +name: version, tag and github release |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [main] |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - uses: actions/checkout@v4 |
| 13 | + - uses: actions/setup-node@v4 |
| 14 | + - name: Check if version already exists |
| 15 | + id: version-check |
| 16 | + run: | |
| 17 | + package_version=$(node -p "require('./package.json').version") |
| 18 | + exists=$(gh api repos/${{ github.repository }}/releases/tags/v$package_version >/dev/null 2>&1 && echo "true" || echo "") |
| 19 | +
|
| 20 | + if [ -n "$exists" ]; |
| 21 | + then |
| 22 | + echo "Version v$package_version already exists" |
| 23 | + echo "::warning file=package.json,line=1::Version v$package_version already exists - no release will be created. If you want to create a new release, please update the version in package.json and push again." |
| 24 | + echo "skipped=true" >> $GITHUB_OUTPUT |
| 25 | + else |
| 26 | + echo "Version v$package_version does not exist. Creating release..." |
| 27 | + echo "skipped=false" >> $GITHUB_OUTPUT |
| 28 | + echo "tag=v$package_version" >> $GITHUB_OUTPUT |
| 29 | + fi |
| 30 | + env: |
| 31 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 32 | + - name: Setup git |
| 33 | + if: ${{ steps.version-check.outputs.skipped == 'false' }} |
| 34 | + run: | |
| 35 | + git config --global user.email ${{ secrets.GH_EMAIL }} |
| 36 | + git config --global user.name ${{ secrets.GH_USERNAME }} |
| 37 | + - name: Generate oclif README |
| 38 | + if: ${{ steps.version-check.outputs.skipped == 'false' }} |
| 39 | + id: oclif-readme |
| 40 | + run: | |
| 41 | + pnpm install |
| 42 | + pnpm exec oclif readme |
| 43 | + if [ -n "$(git status --porcelain)" ]; then |
| 44 | + git add . |
| 45 | + git commit -am "chore: update README.md" |
| 46 | + git push -u origin ${{ github.ref_name }} |
| 47 | + fi |
| 48 | + - name: Create Github Release |
| 49 | + uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 |
| 50 | + if: ${{ steps.version-check.outputs.skipped == 'false' }} |
| 51 | + with: |
| 52 | + name: ${{ steps.version-check.outputs.tag }} |
| 53 | + tag: ${{ steps.version-check.outputs.tag }} |
| 54 | + commit: ${{ github.ref_name }} |
| 55 | + token: ${{ secrets.GH_TOKEN }} |
| 56 | + skipIfReleaseExists: true |
0 commit comments