Skip to content

Commit

Permalink
Test the Pre-Release[0]
Browse files Browse the repository at this point in the history
  • Loading branch information
cvetty committed Dec 12, 2024
1 parent b6ab7d2 commit 49b06ac
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 88 deletions.
102 changes: 72 additions & 30 deletions .github/actions/set-release-tag/script.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,80 @@
module.exports = async ({ github, context, inputs }) => {
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: "unreleased",
});
let release = releases.data.find(
(release) =>
release.draft == true &&
release.tag_name === `unreleased[${inputs.branchName}]`,
);
const majorVersion = inputs.branchName.split(".")[0];
const draftTagName = `unreleased[${inputs.branchName}]`;

if (release) {
console.log("Updating the draft release...");
github.rest.repos.updateRelease({
// Filtering the draft releases additionally
// As the draft filter does not work :(
const draftReleases = await github.rest.repos
.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
name: inputs.tagName,
tag_name: inputs.tagName,
draft: false,
prerelease: true,
});
} else {
console.log("Creating a new pre-release...");
release = github.rest.repos.createRelease({
tag_name: draftTagName,
})
.data?.filter((release) => release.draft);

// Filtering the draft releases additionally
// As the prerelease filter does not work :(
const preReleases = await github.rest.repos
.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
name: inputs.tagName,
tag_name: inputs.tagName,
draft: false,
prerelease: true,
generate_release_notes: true,
});
}
})
.data?.filter((release) => release.prerelease);

console.log(draftReleases);
console.log(preReleases);

// // Ensure that the other pre-releases are merged to the current one
// for (const preRelease of preReleases.data) {
// if (preRelease.tag_name.startsWith(`${majorVersion}.`)) {
// // Delete the release
// await github.rest.repos.deleteRelease({
// owner: context.repo.owner,
// repo: context.repo.repo,
// release_id: preRelease.id,
// });

// // Delete the tag
// await github.rest.git.deleteRef({
// owner: context.repo.owner,
// repo: context.repo.repo,
// ref: `tags/${preRelease.tag_name}`,
// });
// }
// }

// let release = draftReleases.data.find(
// (release) => release.tag_name === draftTagName,
// );
// if (release) {
// console.log("Updating the draft release...");
// const notes = await github.rest.repos.generateReleaseNotes({
// owner: context.repo.owner,
// repo: context.repo.repo,
// tag_name: inputs.tagName,
// });
// github.rest.repos.updateRelease({
// owner: context.repo.owner,
// repo: context.repo.repo,
// release_id: release.id,
// name: inputs.tagName,
// body: notes.data.body,
// tag_name: inputs.tagName,
// draft: false,
// prerelease: true,
// });
// } else {
// console.log("Creating a new pre-release...");
// release = github.rest.repos.createRelease({
// owner: context.repo.owner,
// repo: context.repo.repo,
// name: inputs.tagName,
// tag_name: inputs.tagName,
// draft: false,
// prerelease: true,
// generate_release_notes: true,
// });
// }

return release.id;
// return release.id;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ concurrency:
jobs:
draft-release:
name: Draft Github Release
if: github.actor != 'mtrpackageversionsmanager[bot]'
runs-on: ubuntu-22.04
steps:
- name: Checkout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ env:
NODE_VERSION: "20.16.0"

concurrency:
group: release
group: release-${{ github.ref_name }}
cancel-in-progress: false

permissions:
contents: write

jobs:
check_branch:
name: Check the release branch
name: Check the Release Branch
runs-on: ubuntu-22.04
outputs:
major_version: ${{ steps.extract_major_version.outputs.version }}
Expand All @@ -48,14 +48,14 @@ jobs:
echo "version=$MAJOR_VERSION" >> "$GITHUB_OUTPUT"
echo "Extracted major version: $MAJOR_VERSION"
pre_release:
name: Create Pre-Release
set_version:
name: Set Package Version
runs-on: ubuntu-22.04
needs: [check_branch]
outputs:
release_id: ${{ steps.update-release.outputs.release_id }}
version: ${{ steps.pre_release_version.outputs.version }}
steps:
- name: Get Token
- name: Get the github token
id: get_workflow_token
uses: peter-murray/workflow-application-token-action@v3
with:
Expand All @@ -65,8 +65,6 @@ jobs:
- name: Checkout the repo
uses: actions/checkout@v4
with:
ref: main
lfs: false
token: ${{ steps.get_workflow_token.outputs.token }}

- name: Install NodeJS
Expand All @@ -80,6 +78,7 @@ jobs:
git config user.name "github-actions[bot]"
- name: Ensure that the major version matches the branch
working-directory: krait-ui
env:
MAJOR_VERSION: ${{ needs.check_branch.outputs.major_version }}
run: |
Expand All @@ -92,80 +91,87 @@ jobs:
fi
- name: Update version in package.json
working-directory: krait-ui
if: github.event.inputs.version-update != 'no update'
run: npm version $VERSION_UPDATE --no-git-tag-version
working-directory: krait-ui
env:
VERSION_UPDATE: ${{ github.event.inputs.version-update }}
run: npm version $VERSION_UPDATE --no-git-tag-version

- name: Set the version as pre-release(beta)
id: create_tag
- name: Set the version as pre-release(beta version)
id: pre_release_version
working-directory: krait-ui
env:
GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }}
run: |
TAG=$(npm version prerelease --preid=beta)
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
VERSION=$(npm version prerelease --preid=beta)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
# - name: Commit the version update
# env:
# TAG_NAME: ${{ steps.create_tag.outputs.tag }}
# VERSION: ${{ steps.pre_release_version.outputs.version }}
# run: |
# git commit -am "[GHA] Update package version to $TAG_NAME"
# git commit -am "[GHA] Update package version to $VERSION"
# git push

- name: Set pre-release tag
id: update-release
uses: ./.github/actions/set-release-tag
with:
# branch_name: ${{ github.ref_name }}
branch_name: 1.x
tag_name: ${{ steps.create_tag.outputs.tag }}

# build_ui:
# name: Build UI Library
# needs: [pre_release]
# runs-on: ubuntu-20.04
# needs: [set_version]
# runs-on: ubuntu-22.04
# steps:
# - name: Get Token
# id: get_workflow_token
# uses: peter-murray/workflow-application-token-action@v3
# with:
# application_id: ${{ vars.GH_MTR_PACKAGE_VERSIONS_APP_ID }}
# application_private_key: ${{ secrets.GH_MTR_PACKAGE_VERSIONS_APP_SECRET }}

# - name: Checkout the repo
# uses: actions/checkout@v4
# with:
# ref: main
# lfs: false
# token: ${{ steps.get_workflow_token.outputs.token }}

# - name: Install NodeJS
# - name: Install Node.js
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.NODE_VERSION }}
# registry-url: "https://registry.npmjs.org"

# - name: Retrieve the npm dependencies cache
# uses: actions/cache@v4
# id: node-modules-cache
# with:
# path: node_modules
# key: npm-dependencies-${{ runner.os }}-${{ hashFiles('krait-ui/package-lock.json') }}
# restore-keys: |
# npm-dependencies-${{ hashFiles('krait-ui/package-lock.json') }}
# npm-dependencies-
# cache: "npm"
# cache-dependency-path: "krait-ui/package-lock.json"

# - name: Install npm dependencies
# if: steps.node-modules-cache.outputs.cache-hit != 'true'
# run: cd krait-ui && npm ci
# working-directory: krait-ui
# run: npm ci

# - name: Build FE assets
# run: cd krait-ui && npm run build
# working-directory: krait-ui
# run: npm run build

# - name: Zip the distribution build
# run: cd krait-ui && zip -9qry "distribution-package.zip" "./" -i "dist/*" "package.json" "package-lock.json"
# working-directory: krait-ui
# run: zip -9qry "distribution-package.zip" "./" -i "dist/*" "package.json" "package-lock.json"

# - uses: actions/upload-artifact@v4
# with:
# name: distribution-package.zip
# path: krait-ui/distribution-package.zip

pre_release:
name: Create Pre-Release
runs-on: ubuntu-22.04
needs: [set_version]
outputs:
release_id: ${{ steps.update-release.outputs.release_id }}
steps:
- name: Checkout the repo
uses: actions/checkout@v4

- name: Set pre-release tag
id: update-release
uses: ./.github/actions/set-release-tag
with:
branch_name: ${{ github.ref_name }}
tag_name: ${{ needs.set_version.outputs.version }}

# publish_npm_package:
# name: Publish the UI NPM package
# runs-on: ubuntu-22.04
# needs: [pre_release, build_ui]
# steps:
# - name: Download the distribution build
# uses: actions/download-artifact@v4
# with:
# name: distribution-package.zip
# path: ./distribution-package.zip

# - name: Upload an Asset in GitHub Release
# uses: actions/github-script@v6
Expand All @@ -179,12 +185,13 @@ jobs:
# owner: context.repo.owner,
# repo: context.repo.repo,
# release_id: ${{ env.RELEASE_ID }},
# data: await fs.readFile('./krait-ui/distribution-package.zip')
# data: await fs.readFile('./distribution-package.zip')
# });
# env:
# RELEASE_ID: ${{ needs.prerelease.outputs.release_id }}
# RELEASE_ID: ${{ needs.pre_release.outputs.release_id }}

# - name: Publish the NPM package
# run: cd krait-ui && npm publish --access public --tag dev
# working-directory: krait-ui
# run: npm publish --access public --tag dev
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ jobs:
- name: Install npm dependencies
run: npm ci

- name: Run Prettier Check
- name: Run Prettier check
run: npm run prettier

- name: Run Lint Check
- name: Run Lint check
run: npm run lint

- name: Build
Expand Down

0 comments on commit 49b06ac

Please sign in to comment.