|
| 1 | +name: version, tag and github release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +jobs: |
| 8 | + release: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v4 |
| 12 | + |
| 13 | + - uses: actions/setup-node@v4 |
| 14 | + |
| 15 | + - name: Check if version already exists |
| 16 | + id: version-check |
| 17 | + run: | |
| 18 | + package_version=$(node -p "require('./package.json').version") |
| 19 | + exists=$(gh api repos/${{ github.repository }}/releases/tags/v$package_version >/dev/null 2>&1 && echo "true" || echo "") |
| 20 | +
|
| 21 | + if [ -n "$exists" ]; 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 | + |
| 33 | + - name: Debug Git Config Secrets (optional) |
| 34 | + if: ${{ steps.version-check.outputs.skipped == 'false' }} |
| 35 | + run: | |
| 36 | + echo "GH_EMAIL is set: ${{ secrets.GH_EMAIL != '' }}" |
| 37 | + echo "GH_USERNAME is set: ${{ secrets.GH_USERNAME != '' }}" |
| 38 | +
|
| 39 | + - name: Setup git |
| 40 | + if: ${{ steps.version-check.outputs.skipped == 'false' }} |
| 41 | + run: | |
| 42 | + git config --global user.email "${{ secrets.GH_EMAIL || 'mdirshadengineer+github@gmail.com' }}" |
| 43 | + git config --global user.name "${{ secrets.GH_USERNAME || 'github-actions[bot]' }}" |
| 44 | +
|
| 45 | + - name: Generate oclif README |
| 46 | + if: ${{ steps.version-check.outputs.skipped == 'false' }} |
| 47 | + id: oclif-readme |
| 48 | + run: | |
| 49 | + npm install |
| 50 | + npm exec oclif readme |
| 51 | + if [ -n "$(git status --porcelain)" ]; then |
| 52 | + git add . |
| 53 | + git commit -am "chore: update README.md" |
| 54 | + git push -u origin ${{ github.ref_name }} |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Create Github Release |
| 58 | + uses: ncipollo/release-action@v1 |
| 59 | + if: ${{ steps.version-check.outputs.skipped == 'false' }} |
| 60 | + with: |
| 61 | + name: ${{ steps.version-check.outputs.tag }} |
| 62 | + tag: ${{ steps.version-check.outputs.tag }} |
| 63 | + commit: ${{ github.ref_name }} |
| 64 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + skipIfReleaseExists: true |
0 commit comments