-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
154 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters