From a1b4fdfe0335abe4967e6792f722f0b682b24ef0 Mon Sep 17 00:00:00 2001 From: Mateusz Wronski Date: Mon, 20 Jan 2025 13:45:48 +0100 Subject: [PATCH 1/5] the release job updates versions, creates readme and release PR --- .github/workflows/deploy-release.yaml | 80 ++++++++++++++++++++++++ .github/workflows/release-on-github.yaml | 62 +++--------------- 2 files changed, 89 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/deploy-release.yaml diff --git a/.github/workflows/deploy-release.yaml b/.github/workflows/deploy-release.yaml new file mode 100644 index 0000000..88bbb9d --- /dev/null +++ b/.github/workflows/deploy-release.yaml @@ -0,0 +1,80 @@ +name: Deployment + +run-name: 'Release from ${{ github.ref_name }}' + +on: + pull_request: + branches: + - main + 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 + 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 tag ${{ env.VERSION }} + - name: Push the tag to the repository + run: git push origin ${{ env.VERSION }} + + publish-github: + runs-on: ubuntu-latest + needs: version-and-tag + + permissions: + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - 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 + + - run: 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 From 233a92be0165b0d1dac40104b65018760fc23f32 Mon Sep 17 00:00:00 2001 From: Mateusz Wronski Date: Mon, 20 Jan 2025 14:43:43 +0100 Subject: [PATCH 2/5] testing the CI without any CI mutation --- .github/workflows/deploy-release.yaml | 40 ++++++++++++++++----------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/.github/workflows/deploy-release.yaml b/.github/workflows/deploy-release.yaml index 88bbb9d..f5b7432 100644 --- a/.github/workflows/deploy-release.yaml +++ b/.github/workflows/deploy-release.yaml @@ -5,7 +5,7 @@ run-name: 'Release from ${{ github.ref_name }}' on: pull_request: branches: - - main + - test types: - closed @@ -27,8 +27,10 @@ jobs: # tag the commit with the version and push the tag - name: Tag the commit with the version run: git tag ${{ env.VERSION }} - - name: Push the tag to the repository - run: git push origin ${{ env.VERSION }} + - name: Push the ${{ env.VERSION }} tag to the repository + run: | + echo "Pushing tag $VERSION" +# git push origin ${{ env.VERSION }} publish-github: runs-on: ubuntu-latest @@ -37,22 +39,26 @@ jobs: permissions: contents: write + env: + VERSION: ${{ needs.version-and-tag.outputs.VERSION }} + steps: - name: Checkout repository uses: actions/checkout@v3 - - 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 }} + - run: echo "Creating GitHub release for version $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 @@ -75,6 +81,8 @@ jobs: - run: npm ci - - run: npm publish + - run: | + echo "Publishing version $VERSION to npm" +# npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file From 513b8e3e047d0ba6578e029f9fcd99b5233061d6 Mon Sep 17 00:00:00 2001 From: Mateusz Wronski Date: Mon, 20 Jan 2025 15:06:24 +0100 Subject: [PATCH 3/5] few fixes to CI needed --- .github/workflows/deploy-release.yaml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-release.yaml b/.github/workflows/deploy-release.yaml index f5b7432..b36dec0 100644 --- a/.github/workflows/deploy-release.yaml +++ b/.github/workflows/deploy-release.yaml @@ -26,11 +26,14 @@ jobs: echo "Source branch version: $VERSION" # tag the commit with the version and push the tag - name: Tag the commit with the version - run: git tag ${{ env.VERSION }} - - name: Push the ${{ env.VERSION }} tag to the repository + 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 ${{ env.VERSION }} +# git push origin "$VERSION" --follow-tags publish-github: runs-on: ubuntu-latest @@ -46,7 +49,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - run: echo "Creating GitHub release for version $VERSION" + - run: echo "Creating GitHub release for version ${{ env.VERSION }}" # - name: Create GitHub Release # uses: octokit/request-action@v2.x # id: create_release @@ -81,7 +84,8 @@ jobs: - run: npm ci - - run: | + - name: Publish swaggerhub-cli ${{ env.VERSION }} to npm + run: | echo "Publishing version $VERSION to npm" # npm publish env: From 6cc6717d33f733022421d1382b341a75d9102dff Mon Sep 17 00:00:00 2001 From: Mateusz Wronski Date: Mon, 20 Jan 2025 15:23:23 +0100 Subject: [PATCH 4/5] dependency not found --- .github/workflows/deploy-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-release.yaml b/.github/workflows/deploy-release.yaml index b36dec0..fea1017 100644 --- a/.github/workflows/deploy-release.yaml +++ b/.github/workflows/deploy-release.yaml @@ -37,7 +37,7 @@ jobs: publish-github: runs-on: ubuntu-latest - needs: version-and-tag + needs: [ version-and-tag ] permissions: contents: write From fdb986f43337577317dbaacf3ee19a2b984dcea3 Mon Sep 17 00:00:00 2001 From: Mateusz Wronski Date: Mon, 20 Jan 2025 15:31:36 +0100 Subject: [PATCH 5/5] output not transferred to subsequent jobse --- .github/workflows/deploy-release.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/deploy-release.yaml b/.github/workflows/deploy-release.yaml index fea1017..ce1da71 100644 --- a/.github/workflows/deploy-release.yaml +++ b/.github/workflows/deploy-release.yaml @@ -13,6 +13,10 @@ 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