-
Notifications
You must be signed in to change notification settings - Fork 5
chore: switch to Trusted Publishing #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # | ||
| # Copyright (c) 2022-2024 | ||
| # This program and the accompanying materials are made | ||
| # available under the terms of the Eclipse Public License 2.0 | ||
| # which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| # | ||
| # SPDX-License-Identifier: EPL-2.0 | ||
| # | ||
|
|
||
| # Main workflow for building and publishing release builds | ||
| # Release commit | ||
| name: Publish project to npmjs | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| release-version: | ||
| description: 'release version in format 7.y.z' | ||
| required: true | ||
| release-remake: | ||
| description: 'set to true to recreate existing tags (otherwise release will fail if tags already exist)' | ||
| type: boolean | ||
| default: false | ||
| required: true | ||
| push: | ||
| branches: | ||
| - main | ||
| - 7.**.x | ||
|
|
||
| permissions: | ||
| id-token: write # Required for publishing to npmjs | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| publish: | ||
| name: Build and publish DevWorkspace Generator to npmjs | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - name: Validate parameters and build type | ||
| shell: bash | ||
| id: dist-tag-eval | ||
| run: | | ||
| # check if workflow is triggered manually (release) or via branch push (next build) | ||
| # release will always be performed as workflow_dispatch trigger, while push triggers are for dev/next builds | ||
| # based on this information, we determine the dist-tag for pushing to npmjs | ||
| DIST_TAG= | ||
| if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then | ||
| RELEASE_VERSION=${{ github.event.inputs.release-version }} | ||
| if [[ "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "[INFO]" preparing to build and release with version: $RELEASE_VERSION | ||
| # DIST_TAG is not used in make-release.sh, as release version will always be latest anyway | ||
| DIST_TAG=latest | ||
| else | ||
| echo "[ERROR] incorrect version "$RELEASE_VERSION". Must be following format <number>.<number>.<number>, e.g. 7.111.0" | ||
| exit 1 | ||
| fi | ||
| fi | ||
| if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then | ||
| if [[ ${GITHUB_REF##*/} == "7."**".x" ]]; then | ||
| echo "[INFO] using ${GITHUB_REF##*/} tag" | ||
| DIST_TAG="next-${GITHUB_REF##*/}" | ||
| else | ||
| echo "[INFO] using "next" tag" | ||
| DIST_TAG=next | ||
| fi | ||
| fi | ||
| echo "npm_dist_tag=$DIST_TAG" >> $GITHUB_OUTPUT | ||
|
Comment on lines
+40
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow GitHub Actions security best practice for user input handling. Line 49 directly expands Best practice is to pass user inputs through environment variables: 🔒 Recommended fix: use environment variables - name: Validate parameters and build type
shell: bash
id: dist-tag-eval
+ env:
+ RELEASE_VERSION: ${{ github.event.inputs.release-version }}
run: |
# check if workflow is triggered manually (release) or via branch push (next build)
# release will always be performed as workflow_dispatch trigger, while push triggers are for dev/next builds
# based on this information, we determine the dist-tag for pushing to npmjs
DIST_TAG=
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
- RELEASE_VERSION=${{ github.event.inputs.release-version }}
if [[ "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; thenApply the same pattern to lines 79-80 and 121 where inputs are expanded. 🧰 Tools🪛 zizmor (1.25.2)[error] 49-49: code injection via template expansion (template-injection): may expand into attacker-controllable code (template-injection) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
| - name: "Checkout source code" | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Check existing release tags | ||
| if: github.event_name == 'workflow_dispatch' | ||
| env: | ||
| GITHUB_TOKEN: ${{secrets.DEVWORKSPACE_GENERATOR_RELEASE_GITHUB_TOKEN}} | ||
| run: | | ||
| set +e | ||
| RECREATE_TAGS=${{ github.event.inputs.release-remake }} | ||
| VERSION=${{ github.event.inputs.release-version }} | ||
| EXISTING_TAG=$(git ls-remote --exit-code origin refs/tags/${VERSION}) | ||
| if [[ -n ${EXISTING_TAG} ]]; then | ||
| if [[ ${RECREATE_TAGS} == "true" ]]; then | ||
| echo "[INFO] Removing tag for ${VERSION} version. New tag will be recreated during release." | ||
| git push origin :${VERSION} | ||
| else | ||
| echo "[ERROR] Cannot proceed with release - tag ${EXISTING_TAG} already exists." | ||
| exit 1 | ||
| fi | ||
| else | ||
| echo "[INFO] No existing tags detected for ${VERSION}" | ||
| fi | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '24' | ||
| registry-url: 'https://registry.npmjs.org' | ||
| scope: '@eclipse-che' | ||
| - name: Set up environment | ||
| run: | | ||
| sudo apt-get update -y || true | ||
| sudo apt-get -y -q install hub | ||
| hub --version | ||
| - name: Get yarn cache directory path | ||
| id: yarn-cache-dir-path | ||
| run: | | ||
| echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT | ||
| - uses: actions/cache@v4 | ||
| id: yarn-cache | ||
| with: | ||
| path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
| key: yarn-${{ hashFiles('yarn.lock') }} | ||
| restore-keys: yarn- | ||
| - name: Build and publish release version | ||
|
svor marked this conversation as resolved.
|
||
| if: github.event_name == 'workflow_dispatch' | ||
| env: | ||
| GITHUB_TOKEN: ${{secrets.DEVWORKSPACE_GENERATOR_RELEASE_GITHUB_TOKEN}} | ||
| run: | | ||
| git config --global user.name "Mykhailo Kuznietsov" | ||
| git config --global user.email "mkuznets@redhat.com" | ||
|
|
||
| ./make-release.sh --version ${{ github.event.inputs.release-version }} | ||
| - name: Build and publish next version | ||
| if: github.event_name == 'push' | ||
| run: | | ||
| SHORT_SHA1=$(git rev-parse --short=7 HEAD) | ||
|
svor marked this conversation as resolved.
|
||
| CURRENT_VERSION=$(jq -r '.version' package.json) | ||
| NEW_VERSION="${CURRENT_VERSION}-${SHORT_SHA1}" | ||
| echo New version is ${NEW_VERSION} | ||
| sed -i -r -e "s/(\"version\": )(\".*\")/\1\"$NEW_VERSION\"/" package.json | ||
|
|
||
| # build | ||
| yarn | ||
| yarn compile | ||
|
|
||
| npm publish --tag ${{ steps.dist-tag-eval.outputs.npm_dist_tag }} | ||
Uh oh!
There was an error while loading. Please reload this page.