Merge pull request #18 from mcpgod/yrnfg0-codex/add-github-action-for… #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # test | |
| name: version, tag and github release | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: latest | |
| - name: Check if version already exists | |
| id: version-check | |
| shell: bash | |
| run: | | |
| package_name="$(node -p "require('./package.json').name")" | |
| package_version="$(node -p "require('./package.json').version")" | |
| gh_exists="$(gh api \ | |
| "repos/${{ github.repository }}/releases/tags/v${package_version}" \ | |
| >/dev/null 2>&1 && echo 'true' || echo '')" | |
| npm_exists="$(npm view "${package_name}@${package_version}" --json \ | |
| >/dev/null 2>&1 && echo 'true' || echo '')" | |
| if [[ -n "$gh_exists" || -n "$npm_exists" ]]; then | |
| echo "::warning file=package.json,line=1::Version v${package_version} already exists—skipping release." | |
| echo "skipped=true" >>"${GITHUB_OUTPUT}" | |
| else | |
| echo "skipped=false" >>"${GITHUB_OUTPUT}" | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup git | |
| if: ${{ steps.version-check.outputs.skipped == 'false' }} | |
| run: | | |
| git config --global user.email ${{ secrets.GH_EMAIL }} | |
| git config --global user.name ${{ secrets.GH_USERNAME }} | |
| - name: Generate oclif README | |
| if: ${{ steps.version-check.outputs.skipped == 'false' }} | |
| id: oclif-readme | |
| run: | | |
| npm install | |
| npm exec oclif readme | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git add . | |
| git commit -am "chore: update README.md" | |
| git push -u origin ${{ github.ref_name }} | |
| fi | |
| - name: Create Github Release | |
| uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 | |
| if: ${{ steps.version-check.outputs.skipped == 'false' }} | |
| with: | |
| name: ${{ steps.version-check.outputs.tag }} | |
| tag: ${{ steps.version-check.outputs.tag }} | |
| commit: ${{ github.ref_name }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| skipIfReleaseExists: true | |
| - name: Install dependencies | |
| if: ${{ steps.version-check.outputs.skipped == 'false' }} | |
| run: npm install | |
| - name: Build | |
| if: ${{ steps.version-check.outputs.skipped == 'false' }} | |
| run: npm run build | |
| - name: Prepare package | |
| if: ${{ steps.version-check.outputs.skipped == 'false' }} | |
| run: npm run prepack | |
| - name: Publish to npm | |
| uses: JS-DevTools/npm-publish@19c28f1ef146469e409470805ea4279d47c3d35c | |
| if: ${{ steps.version-check.outputs.skipped == 'false' }} | |
| with: | |
| token: ${{ secrets.NPM_TOKEN }} | |
| - name: Cleanup package | |
| if: ${{ steps.version-check.outputs.skipped == 'false' }} | |
| run: npm run postpack |