Skip to content

Commit dfc7693

Browse files
authored
chore: switch to Trusted Publishing (#389)
Signed-off-by: Mykhailo Kuznietsov <mkuznets@redhat.com>
1 parent 19723d1 commit dfc7693

3 files changed

Lines changed: 135 additions & 135 deletions

File tree

.github/workflows/devworkspace-generator-publish-next.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/devworkspace-generator-release.yml

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#
2+
# Copyright (c) 2022-2024
3+
# This program and the accompanying materials are made
4+
# available under the terms of the Eclipse Public License 2.0
5+
# which is available at https://www.eclipse.org/legal/epl-2.0/
6+
#
7+
# SPDX-License-Identifier: EPL-2.0
8+
#
9+
10+
# Main workflow for building and publishing release builds
11+
# Release commit
12+
name: Publish project to npmjs
13+
14+
on:
15+
workflow_dispatch:
16+
inputs:
17+
release-version:
18+
description: 'release version in format 7.y.z'
19+
required: true
20+
release-remake:
21+
description: 'set to true to recreate existing tags (otherwise release will fail if tags already exist)'
22+
type: boolean
23+
default: false
24+
required: true
25+
push:
26+
branches:
27+
- main
28+
- 7.**.x
29+
30+
permissions:
31+
id-token: write # Required for publishing to npmjs
32+
contents: write
33+
pull-requests: write
34+
35+
jobs:
36+
publish:
37+
name: Build and publish DevWorkspace Generator to npmjs
38+
runs-on: ubuntu-22.04
39+
steps:
40+
- name: Validate parameters and build type
41+
shell: bash
42+
id: dist-tag-eval
43+
run: |
44+
# check if workflow is triggered manually (release) or via branch push (next build)
45+
# release will always be performed as workflow_dispatch trigger, while push triggers are for dev/next builds
46+
# based on this information, we determine the dist-tag for pushing to npmjs
47+
DIST_TAG=
48+
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
49+
RELEASE_VERSION=${{ github.event.inputs.release-version }}
50+
if [[ "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
51+
echo "[INFO]" preparing to build and release with version: $RELEASE_VERSION
52+
# DIST_TAG is not used in make-release.sh, as release version will always be latest anyway
53+
DIST_TAG=latest
54+
else
55+
echo "[ERROR] incorrect version "$RELEASE_VERSION". Must be following format <number>.<number>.<number>, e.g. 7.111.0"
56+
exit 1
57+
fi
58+
fi
59+
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
60+
if [[ ${GITHUB_REF##*/} == "7."**".x" ]]; then
61+
echo "[INFO] using ${GITHUB_REF##*/} tag"
62+
DIST_TAG="next-${GITHUB_REF##*/}"
63+
else
64+
echo "[INFO] using "next" tag"
65+
DIST_TAG=next
66+
fi
67+
fi
68+
echo "npm_dist_tag=$DIST_TAG" >> $GITHUB_OUTPUT
69+
- name: "Checkout source code"
70+
uses: actions/checkout@v4
71+
with:
72+
fetch-depth: 0
73+
- name: Check existing release tags
74+
if: github.event_name == 'workflow_dispatch'
75+
env:
76+
GITHUB_TOKEN: ${{secrets.DEVWORKSPACE_GENERATOR_RELEASE_GITHUB_TOKEN}}
77+
run: |
78+
set +e
79+
RECREATE_TAGS=${{ github.event.inputs.release-remake }}
80+
VERSION=${{ github.event.inputs.release-version }}
81+
EXISTING_TAG=$(git ls-remote --exit-code origin refs/tags/${VERSION})
82+
if [[ -n ${EXISTING_TAG} ]]; then
83+
if [[ ${RECREATE_TAGS} == "true" ]]; then
84+
echo "[INFO] Removing tag for ${VERSION} version. New tag will be recreated during release."
85+
git push origin :${VERSION}
86+
else
87+
echo "[ERROR] Cannot proceed with release - tag ${EXISTING_TAG} already exists."
88+
exit 1
89+
fi
90+
else
91+
echo "[INFO] No existing tags detected for ${VERSION}"
92+
fi
93+
- uses: actions/setup-node@v4
94+
with:
95+
node-version: '24'
96+
registry-url: 'https://registry.npmjs.org'
97+
scope: '@eclipse-che'
98+
- name: Set up environment
99+
run: |
100+
sudo apt-get update -y || true
101+
sudo apt-get -y -q install hub
102+
hub --version
103+
- name: Get yarn cache directory path
104+
id: yarn-cache-dir-path
105+
run: |
106+
echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
107+
- uses: actions/cache@v4
108+
id: yarn-cache
109+
with:
110+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
111+
key: yarn-${{ hashFiles('yarn.lock') }}
112+
restore-keys: yarn-
113+
- name: Build and publish release version
114+
if: github.event_name == 'workflow_dispatch'
115+
env:
116+
GITHUB_TOKEN: ${{secrets.DEVWORKSPACE_GENERATOR_RELEASE_GITHUB_TOKEN}}
117+
run: |
118+
git config --global user.name "Mykhailo Kuznietsov"
119+
git config --global user.email "mkuznets@redhat.com"
120+
121+
./make-release.sh --version ${{ github.event.inputs.release-version }}
122+
- name: Build and publish next version
123+
if: github.event_name == 'push'
124+
run: |
125+
SHORT_SHA1=$(git rev-parse --short=7 HEAD)
126+
CURRENT_VERSION=$(jq -r '.version' package.json)
127+
NEW_VERSION="${CURRENT_VERSION}-${SHORT_SHA1}"
128+
echo New version is ${NEW_VERSION}
129+
sed -i -r -e "s/(\"version\": )(\".*\")/\1\"$NEW_VERSION\"/" package.json
130+
131+
# build
132+
yarn
133+
yarn compile
134+
135+
npm publish --tag ${{ steps.dist-tag-eval.outputs.npm_dist_tag }}

0 commit comments

Comments
 (0)