Skip to content

Commit

Permalink
Improve the CI/CD process (#112)
Browse files Browse the repository at this point in the history
* Improve the CI/CD process
  • Loading branch information
cvetty committed Dec 13, 2024
1 parent 3cebcf6 commit 01ad244
Show file tree
Hide file tree
Showing 10 changed files with 352 additions and 315 deletions.
23 changes: 23 additions & 0 deletions .github/actions/draft-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Draft Release"
description: "Creates or updates a draft release"

inputs:
branch_name:
description: "The target branch name (1.x, 2.x, etc.)"
required: true

runs:
using: "composite"
steps:
- name: Draft github release
uses: actions/github-script@v6
with:
script: |
const script = require('${{ github.action_path }}/script.js')
await script({
github,
context,
inputs: {
branchName: '${{ inputs.branch_name }}'
}
})
43 changes: 43 additions & 0 deletions .github/actions/draft-release/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = async ({ github, context, inputs }) => {
const tagName = `unreleased[${inputs.branchName}]`;
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
});

const filtered = releases.data.filter(
(release) => release.draft == true && release.tag_name === tagName,
);

if (filtered.length > 0) {
console.log("Deleting old untagged release");
await github.rest.repos.deleteRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: filtered[0].id,
});

try {
console.log(`Deleting old '${tagName}' tag`);
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${tagName}`,
});
console.log(`The '${tagName}' tag has been deleted`);
} catch (error) {
console.log(`Tag '${tagName}' does not exist or could not be deleted`);
}
}

console.log(`Creating a new untagged release for ${inputs.branchName}`);
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
name: `Unreleased [${inputs.branchName}]`,
draft: true,
generate_release_notes: true,
});
};
33 changes: 33 additions & 0 deletions .github/actions/set-release-tag/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Set Release Tag"
description: "Updates the tag of specific release"

inputs:
branch_name:
description: "The target branch name (1.x, 2.x, etc.)"
required: true
tag_name:
description: "The target tag name"
required: true

outputs:
release_id:
description: "The result from the release tag update operation"
value: ${{ steps.set-release-tag.outputs.result }}

runs:
using: "composite"
steps:
- name: Set release tag
uses: actions/github-script@v6
id: set-release-tag
with:
script: |
const script = require('${{ github.action_path }}/script.js')
return await script({
github,
context,
inputs: {
branchName: '${{ inputs.branch_name }}',
tagName: '${{ inputs.tag_name }}'
}
})
38 changes: 38 additions & 0 deletions .github/actions/set-release-tag/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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}]`,
);

if (release) {
console.log("Updating the draft release...");
github.rest.repos.updateRelease({
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({
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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI Validation
on:
pull_request:
branches:
- main
- "[0-9]+.x"

defaults:
run:
Expand Down
66 changes: 0 additions & 66 deletions .github/workflows/draft-release.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/draft_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Draft Release
run-name: Draft Release latest updates of ${{ github.ref_name }} (@${{ github.actor }})

on:
push:
branches:
- "[0-9]+.x"

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

jobs:
draft-release:
name: Draft Github Release
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Create/Update Draft Release
uses: ./.github/actions/draft-release
with:
branch_name: ${{ github.ref_name }}
Loading

0 comments on commit 01ad244

Please sign in to comment.