|
| 1 | +name: Xelp Shadow Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + shadow-release: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + permissions: |
| 10 | + contents: write |
| 11 | + steps: |
| 12 | + - name: Checkout xelp/main |
| 13 | + uses: actions/checkout@v4 |
| 14 | + with: |
| 15 | + ref: xelp/main |
| 16 | + fetch-depth: 0 |
| 17 | + |
| 18 | + - name: Setup Node.js |
| 19 | + uses: actions/setup-node@v4 |
| 20 | + with: |
| 21 | + node-version: '18' |
| 22 | + |
| 23 | + - name: Configure Git |
| 24 | + run: | |
| 25 | + git config user.name "github-actions[bot]" |
| 26 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 27 | +
|
| 28 | + - name: Calculate XelpShadow Version |
| 29 | + id: version |
| 30 | + run: | |
| 31 | + CURRENT_VERSION=$(node -p "require('./package.json').version") |
| 32 | + PACKAGE_NAME=$(node -p "require('./package.json').name") |
| 33 | + echo "Current version: $CURRENT_VERSION" |
| 34 | + echo "Package name: $PACKAGE_NAME" |
| 35 | + echo "package_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT |
| 36 | +
|
| 37 | + # Remove pre-release and build metadata |
| 38 | + BASE_VERSION=$(echo "$CURRENT_VERSION" | sed 's/[-+].*//') |
| 39 | +
|
| 40 | + # Split version into parts |
| 41 | + IFS='.' read -r -a PARTS <<< "$BASE_VERSION" |
| 42 | + if [ ${#PARTS[@]} -ne 3 ]; then |
| 43 | + echo "Error: Version must be in MAJOR.MINOR.PATCH format" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + MAJOR="${PARTS[0]}" |
| 47 | + MINOR="${PARTS[1]}" |
| 48 | + PATCH="${PARTS[2]}" |
| 49 | +
|
| 50 | + # Get build metadata |
| 51 | + DATE=$(date +'%Y%m%d') |
| 52 | + SHORT_HASH=$(git rev-parse --short HEAD) |
| 53 | +
|
| 54 | + # Construct base version: MAJOR.MINOR.DATE<PATCH> |
| 55 | + CLEAN_VERSION="$MAJOR.$MINOR.$DATE$PATCH" |
| 56 | +
|
| 57 | + # Full version with metadata for the tag message/release notes |
| 58 | + METADATA_VERSION="$CLEAN_VERSION+xelp-$SHORT_HASH" |
| 59 | +
|
| 60 | + # Use clean version for package.json and git tag (no + or -) |
| 61 | + PACKAGE_VERSION="$CLEAN_VERSION" |
| 62 | + TAG_VERSION="$CLEAN_VERSION" |
| 63 | +
|
| 64 | + echo "Clean version: $CLEAN_VERSION" |
| 65 | + echo "Metadata version: $METADATA_VERSION" |
| 66 | +
|
| 67 | + echo "package_version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT |
| 68 | + echo "tag_version=$TAG_VERSION" >> $GITHUB_OUTPUT |
| 69 | + echo "metadata_version=$METADATA_VERSION" >> $GITHUB_OUTPUT |
| 70 | + - name: Install dependencies |
| 71 | + run: npm ci |
| 72 | + |
| 73 | + - name: Update package.json version |
| 74 | + run: | |
| 75 | + npm version ${{ steps.version.outputs.package_version }} --no-git-tag-version |
| 76 | +
|
| 77 | + - name: Build |
| 78 | + run: npm run build |
| 79 | + |
| 80 | + - name: Commit and Push |
| 81 | + env: |
| 82 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + run: | |
| 84 | + set -e |
| 85 | + git checkout -b xelp/dist |
| 86 | + git add -f dist/ package.json package-lock.json |
| 87 | + git commit -m "Release shadow version ${{ steps.version.outputs.package_version }}" |
| 88 | + git tag -a "${{ steps.version.outputs.tag_version }}" -m "Shadow release ${{ steps.version.outputs.metadata_version }}" |
| 89 | + git push origin xelp/dist --force |
| 90 | + git push origin "${{ steps.version.outputs.tag_version }}" --force |
| 91 | +
|
| 92 | + - name: Create Release |
| 93 | + env: |
| 94 | + GH_TOKEN: ${{ secrets.GH_PAT }} |
| 95 | + run: | |
| 96 | + gh release create "${{ steps.version.outputs.tag_version }}" \ |
| 97 | + --repo $GITHUB_REPOSITORY \ |
| 98 | + --title "Shadow Release ${{ steps.version.outputs.tag_version }}" \ |
| 99 | + --notes "Shadow release build ${{ steps.version.outputs.metadata_version }} |
| 100 | +
|
| 101 | + ## package.json |
| 102 | + \`\`\`json |
| 103 | + \"${{ steps.version.outputs.package_name }}\": \"https://github.com/${{ github.repository }}.git#${{ steps.version.outputs.tag_version }}\" |
| 104 | + \`\`\`" \ |
| 105 | + --prerelease |
0 commit comments