|
| 1 | +name: Backstage plugin release |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - 'release-*' |
| 7 | + paths: |
| 8 | + - 'backstage/plugins/knative-event-mesh-backend/**' |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - 'release-*' |
| 12 | + # Do not run on push to release-next branch. We don't want to publish the plugin on every push to release-next. |
| 13 | + # It might be okay to do so, but sobranch tool doesn't work well with release-next branch name. |
| 14 | + - '!release-next' |
| 15 | +# Ideally, we would want to only publish the plugin on NPM when there's an actual code change in the plugin. |
| 16 | +# However, using the path filters block workflow execution on initial branch creation. |
| 17 | +# So, let's publish on every push to a release branch. |
| 18 | +# see https://github.com/openshift-knative/backstage-plugins/pull/15#issuecomment-2333324099 |
| 19 | +# paths: |
| 20 | +# - 'backstage/plugins/knative-event-mesh-backend/**' |
| 21 | + |
| 22 | +concurrency: |
| 23 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 24 | + |
| 25 | +jobs: |
| 26 | + release: |
| 27 | + name: Release |
| 28 | + runs-on: ubuntu-latest |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - uses: dorny/paths-filter@v3 |
| 35 | + id: changes |
| 36 | + with: |
| 37 | + filters: | |
| 38 | + event_mesh_plugin: |
| 39 | + - 'backstage/plugins/knative-event-mesh-backend/**' |
| 40 | +
|
| 41 | + - name: Setup Golang |
| 42 | + uses: actions/setup-go@v5 |
| 43 | + with: |
| 44 | + go-version-file: go.mod |
| 45 | + |
| 46 | + - name: Checkout openshift-knative/hack |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + repository: 'openshift-knative/hack' |
| 50 | + ref: 'main' |
| 51 | + path: ./src/github.com/openshift-knative/hack |
| 52 | + |
| 53 | + - name: Install sobranch |
| 54 | + run: | |
| 55 | + go install ./cmd/sobranch |
| 56 | + working-directory: ./src/github.com/openshift-knative/hack |
| 57 | + |
| 58 | + - name: Setup release name for release branch push |
| 59 | + # do not run the step on PRs against release-next branch. run it on: |
| 60 | + # PRs against release-* branches, push to release-* branches, and creation of release-* branches |
| 61 | + if: github.event.created || steps.changes.outputs.event_mesh_plugin == 'true' |
| 62 | + run: | |
| 63 | + BRANCH=$(git rev-parse --abbrev-ref HEAD) #e.g. release-v1.33 |
| 64 | + echo "Release branch: ${BRANCH}" |
| 65 | + |
| 66 | + SO_RELEASE_NAME=$( $(go env GOPATH)/bin/sobranch --upstream-version "${BRANCH}") # input format: "release-v1.11" or "release-1.11" or "v1.11" or "1.11" |
| 67 | + # SO_RELEASE_NAME will be something like "release-1.33" |
| 68 | + echo "SO_RELEASE_NAME: ${SO_RELEASE_NAME}" |
| 69 | + |
| 70 | + # split the release name to get the version number |
| 71 | + ## e.g. release-1.33 -> 1.33 |
| 72 | + BASE_RELEASE_VERSION=${SO_RELEASE_NAME#*-} |
| 73 | + echo "BASE_RELEASE_VERSION: ${BASE_RELEASE_VERSION}" |
| 74 | + |
| 75 | + RELEASE_NAME="${BASE_RELEASE_VERSION}.0" |
| 76 | + |
| 77 | + EXISTING_RELEASES="" |
| 78 | + |
| 79 | + if EXISTING_RELEASES=$(npm view @openshift-knative/plugin-knative-event-mesh-backend versions --json); then |
| 80 | + echo "Package information fetched successfully" |
| 81 | + echo "Existing releases: ${EXISTING_RELEASES}" |
| 82 | + PATCH_RELEASES=$(echo "${EXISTING_RELEASES}" | grep ${BASE_RELEASE_VERSION}) |
| 83 | + if [ -z "${PATCH_RELEASES}" ]; then |
| 84 | + echo "No existing PATCH_RELEASES found for ${BASE_RELEASE_VERSION}" |
| 85 | + echo "Going to publish a new .0 patch release" |
| 86 | + RELEASE_NAME="${BASE_RELEASE_VERSION}.0" |
| 87 | + else |
| 88 | + echo "Existing PATCH_RELEASES found for ${BASE_RELEASE_VERSION}" |
| 89 | + PATCH=$(echo "${PATCH_RELEASES}" | tail -1 | tr -d '"' | awk -F \. '{print $3+1}') |
| 90 | + RELEASE_NAME="${BASE_RELEASE_VERSION}.${PATCH}" |
| 91 | + fi |
| 92 | + else |
| 93 | + echo "Error fetching package information. Going to publish a new .0 patch release" |
| 94 | + RELEASE_NAME="${BASE_RELEASE_VERSION}.0" |
| 95 | + fi |
| 96 | + |
| 97 | + echo "RELEASE_NAME: ${RELEASE_NAME}" |
| 98 | + echo "RELEASE_NAME=${RELEASE_NAME}" >> $GITHUB_ENV |
| 99 | +
|
| 100 | + - name: Setup Node.js |
| 101 | + uses: actions/setup-node@v4 |
| 102 | + with: |
| 103 | + node-version-file: 'backstage/.nvmrc' |
| 104 | + cache: 'yarn' |
| 105 | + cache-dependency-path: 'backstage/yarn.lock' |
| 106 | + |
| 107 | + - name: Print environment |
| 108 | + run: | |
| 109 | + node --version |
| 110 | + yarn --version |
| 111 | +
|
| 112 | + - name: Install dependencies |
| 113 | + shell: bash |
| 114 | + working-directory: ./backstage |
| 115 | + run: yarn --prefer-offline --frozen-lockfile |
| 116 | + |
| 117 | + - name: Install tooling |
| 118 | + shell: bash |
| 119 | + working-directory: ./backstage |
| 120 | + run: npm install @backstage/cli -g |
| 121 | + |
| 122 | + - name: Run tests |
| 123 | + shell: bash |
| 124 | + working-directory: ./backstage |
| 125 | + run: | |
| 126 | + export PATH="./node_modules/.bin/:$PATH" |
| 127 | + yarn test |
| 128 | +
|
| 129 | + - name: Build |
| 130 | + shell: bash |
| 131 | + working-directory: ./backstage |
| 132 | + run: | |
| 133 | + export PATH="./node_modules/.bin/:$PATH" |
| 134 | + yarn tsc |
| 135 | + yarn build:all |
| 136 | +
|
| 137 | + - name: Update version of knative-event-mesh-backend plugin |
| 138 | + # do not run the step on PRs against release-next branch. run it on: |
| 139 | + # PRs against release-* branches, push to release-* branches, and creation of release-* branches |
| 140 | + if: github.event.created || steps.changes.outputs.event_mesh_plugin == 'true' |
| 141 | + shell: bash |
| 142 | + working-directory: ./backstage/plugins/knative-event-mesh-backend |
| 143 | + run: | |
| 144 | + export PATH="./node_modules/.bin/:$PATH" |
| 145 | + yarn version --new-version ${RELEASE_NAME} --no-git-tag-version |
| 146 | +
|
| 147 | + - name: Prepack knative-event-mesh-backend plugin |
| 148 | + shell: bash |
| 149 | + working-directory: ./backstage/plugins/knative-event-mesh-backend |
| 150 | + run: | |
| 151 | + export PATH="./node_modules/.bin/:$PATH" |
| 152 | + yarn prepack |
| 153 | +
|
| 154 | + - name: Publish knative-event-mesh-backend plugin |
| 155 | + uses: JS-DevTools/npm-publish@v3 |
| 156 | + # do not run the step on PRs against release-next branch. run it on: |
| 157 | + # PRs against release-* branches, push to release-* branches, and creation of release-* branches |
| 158 | + if: github.event.created || steps.changes.outputs.event_mesh_plugin == 'true' |
| 159 | + with: |
| 160 | + token: ${{ secrets.NPM_TOKEN }} |
| 161 | + access: public |
| 162 | + package: backstage/plugins/knative-event-mesh-backend |
| 163 | + tag: latest |
| 164 | + |
| 165 | + - name: Postpack knative-event-mesh-backend plugin |
| 166 | + shell: bash |
| 167 | + working-directory: ./backstage/plugins/knative-event-mesh-backend |
| 168 | + run: | |
| 169 | + export PATH="./node_modules/.bin/:$PATH" |
| 170 | + yarn postpack |
0 commit comments