From 3e5582cbdab0e79c8d9beee71628f1e041467f6d Mon Sep 17 00:00:00 2001 From: cvetty Date: Thu, 27 Jun 2024 14:50:20 +0300 Subject: [PATCH] Composer package structure updated --- .github/workflows/draft-release.yml | 54 +++++++++++ .github/workflows/pre-release.yml | 135 +++++++++++++++++++-------- krait/composer.json => composer.json | 4 +- 3 files changed, 154 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/draft-release.yml rename krait/composer.json => composer.json (89%) diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml new file mode 100644 index 0000000..f8d1d6e --- /dev/null +++ b/.github/workflows/draft-release.yml @@ -0,0 +1,54 @@ +name: Draft Release + +on: + push: + branches: +# - main + - ci-cd-1 +# paths-ignore: +# - "docs/**" +# - "*.yml" +# - "*.md" + +jobs: + draft-release: + name: Draft Github Release + runs-on: ubuntu-20.04 + steps: + - name: Draft github release + uses: actions/github-script@v6 + with: + script: | + const releases = await github.rest.repos.listReleases({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: "unreleased", + }) + const filtered = releases.data.filter(release => release.draft == true && release.tag_name === 'unreleased'); + if (filtered.length === 0) { + console.log("Creating a new untagged release") + await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: "unreleased", + name: "Unreleased", + draft: true, + generate_release_notes: true, + }) + } else { + console.log("Deleting old untagged release") + await github.rest.repos.deleteRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: filtered[0].id + }) + console.log("Creating a new untagged release") + await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: "unreleased", + name: "Unreleased", + draft: true, + generate_release_notes: true, + }) + } diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 441be4a..73213bc 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -1,54 +1,115 @@ -name: Release +name: Prerelease on: - push: - branches: -# - main - - ci-cd-1 -# paths-ignore: -# - "docs/**" -# - "*.yml" -# - "*.md" + workflow_dispatch: + inputs: + description: + description: 'Release notes' + type: string + default: '' + required: false + version-update: + description: 'Version update' + required: true + default: 'no update' + type: choice + options: + - major + - minor + - patch + - no update + +env: + NODE_VERSION: "18.15.0" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: write jobs: - draft-release: + pre-release: name: Draft Github Release runs-on: ubuntu-20.04 steps: - - name: Draft github release + - name: Checkout the repo + uses: actions/checkout@v4 + with: + ref: main + lfs: false + + - uses: actions/setup-node@v4 + with: + node-version: '18.20.3' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm ci + + - name: Setup Vals + run: | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + + - name: Update package version + if: github.event.inputs.version-update != 'no update' + run: + npm version $VERSION_UPDATE --no-git-tag-version + env: + VERSION_UPDATE: ${{ github.event.inputs.version-update }} + + - name: Update the beta version + id: create_tag + run: | + TAG=$(npm version prerelease --preid=beta -m "[GHA] Update package version to %s") + git push + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + git push --tags + + - name: Set tag uses: actions/github-script@v6 with: script: | + const {TAG_NAME, USER, DESCRIPTION} = process.env const releases = await github.rest.repos.listReleases({ - owner: context.repo.owner, - repo: context.repo.repo, - tag_name: "unreleased", - }) - const filtered = releases.data.filter(release => release.draft == true && release.tag_name === 'unreleased'); - if (filtered.length === 0) { - console.log("Creating a new untagged release") - await github.rest.repos.createRelease({ owner: context.repo.owner, repo: context.repo.repo, tag_name: "unreleased", - name: "Unreleased", - draft: true, - generate_release_notes: true, - }) + }) + const filtered = releases.data.filter(release => release.draft == true && release.tag_name === 'unreleased'); + let release; + if (filtered.length === 0) { + console.log("Creating a new untagged release") + release = await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: "unreleased", + name: "Unreleased", + draft: true, + generate_release_notes: true, + }) } else { - console.log("Deleting old untagged release") - await github.rest.repos.deleteRelease({ - owner: context.repo.owner, - repo: context.repo.repo, - release_id: filtered[0].id - }) - console.log("Creating a new untagged release") - await github.rest.repos.createRelease({ + release = filtered[0]; + } + + let releaseNotes = `${USER} released version ${TAG_NAME}.`; + if (DESCRIPTION) { + releaseNotes += `\n\n Release Notes:\n${DESCRIPTION}`; + } + + github.rest.repos.updateRelease({ owner: context.repo.owner, repo: context.repo.repo, - tag_name: "unreleased", - name: "Unreleased", - draft: true, - generate_release_notes: true, - }) - } + release_id: release.id, + name: TAG_NAME, + tag_name: TAG_NAME, + draft: false, + prerelease: true, + body: releaseNotes, + }); + env: + TAG_NAME: ${{ steps.create_tag.outputs.tag }} + USER: ${{ github.event.sender.login }} + DESCRIPTION: ${{ github.event.inputs.description }} diff --git a/krait/composer.json b/composer.json similarity index 89% rename from krait/composer.json rename to composer.json index 4264d11..f7d97f7 100644 --- a/krait/composer.json +++ b/composer.json @@ -21,12 +21,12 @@ }, "autoload": { "psr-4": { - "MtrDesign\\Krait\\": "src/" + "MtrDesign\\Krait\\": "krait/src/" } }, "autoload-dev": { "psr-4": { - "MtrDesign\\Krait\\Tests\\": "tests/" + "MtrDesign\\Krait\\Tests\\": "krait/tests/" } }, "extra": {