diff --git a/.github/workflows/deploy-release.yaml b/.github/workflows/deploy-release.yaml new file mode 100644 index 0000000..ce1da71 --- /dev/null +++ b/.github/workflows/deploy-release.yaml @@ -0,0 +1,96 @@ +name: Deployment + +run-name: 'Release from ${{ github.ref_name }}' + +on: + pull_request: + branches: + - test + types: + - closed + +jobs: + version-and-tag: + if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/') + runs-on: ubuntu-latest + + outputs: + VERSION: ${{ steps.extract_version.outputs.VERSION }} + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Extract version from source branch name + id: extract_version + run: | + VERSION=${GITHUB_HEAD_REF#release/} + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + echo "Source branch version: $VERSION" + # tag the commit with the version and push the tag + - name: Tag the commit with the version + run: | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + git tag -a $VERSION -m "Release version $VERSION" + - name: Push the tag to the repository + run: | + echo "Pushing tag $VERSION" +# git push origin "$VERSION" --follow-tags + + publish-github: + runs-on: ubuntu-latest + needs: [ version-and-tag ] + + permissions: + contents: write + + env: + VERSION: ${{ needs.version-and-tag.outputs.VERSION }} + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - run: echo "Creating GitHub release for version ${{ env.VERSION }}" +# - name: Create GitHub Release +# uses: octokit/request-action@v2.x +# id: create_release +# with: +# route: POST /repos/{owner}/{repo}/releases +# owner: ${{ github.repository_owner }} +# repo: ${{ github.event.repository.name }} +# tag_name: ${{ env.VERSION }} +# name: ${{ env.VERSION }} +# generate_release_notes: true +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + publish-npm: + runs-on: ubuntu-latest + + needs: [version-and-tag, publish-github] + env: + VERSION: ${{ needs.version-and-tag.outputs.VERSION }} + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ env.VERSION }} + + # Setup .npmrc file to publish to npm + - uses: actions/setup-node@v3 + with: + node-version: '20.x' + registry-url: 'https://registry.npmjs.org' + + - run: npm ci + + - name: Publish swaggerhub-cli ${{ env.VERSION }} to npm + run: | + echo "Publishing version $VERSION to npm" +# npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release-on-github.yaml b/.github/workflows/release-on-github.yaml index 4bcce29..c79a6e4 100644 --- a/.github/workflows/release-on-github.yaml +++ b/.github/workflows/release-on-github.yaml @@ -33,64 +33,20 @@ jobs: - run: npm ci - name: Bump version and regenerate README + id: create_tags run: | # https://github.com/orgs/community/discussions/26560 git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git config user.name "github-actions[bot]" VERSION=$(npm version ${{inputs.type}} --no-git-tag-version) npx oclif readme && node src/format-readme.js - git commit -am "Release for ${VERSION}" - git tag $VERSION + git checkout -b release/${VERSION} echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_OUTPUT - echo "Released version ${VERSION}" >> $GITHUB_STEP_SUMMARY - id: create_tags - - - run: git push origin --follow-tags - - publish-github: - runs-on: ubuntu-latest - - needs: bump-version - permissions: - contents: write - env: - VERSION: ${{ needs.bump-version.outputs.RELEASE_VERSION }} - - steps: - - name: Create GitHub Release - uses: octokit/request-action@v2.x - id: create_release - with: - route: POST /repos/{owner}/{repo}/releases - owner: ${{ github.repository_owner }} - repo: ${{ github.event.repository.name }} - tag_name: ${{ env.VERSION }} - name: ${{ env.VERSION }} - generate_release_notes: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - publish-npm: - runs-on: ubuntu-latest + echo "Release version ${VERSION} PR created" >> $GITHUB_STEP_SUMMARY - needs: [bump-version, publish-github] - env: - VERSION: ${{ needs.bump-version.outputs.RELEASE_VERSION }} - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - ref: ${{ env.VERSION }} - - # Setup .npmrc file to publish to npm - - uses: actions/setup-node@v3 - with: - node-version: '20.x' - registry-url: 'https://registry.npmjs.org' - - - run: npm ci - - - run: npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file + - name: Create release PR + run: | + git commit \ + -am "Release of ${VERSION}" \ + -m "[skip ci]" + git push origin --follow-tags