Skip to content

Commit

Permalink
feat: Update CI (this might break everything)
Browse files Browse the repository at this point in the history
  • Loading branch information
beebls committed Jun 26, 2023
1 parent 4c8299a commit 4b57b61
Show file tree
Hide file tree
Showing 15 changed files with 53,660 additions and 57 deletions.
72 changes: 15 additions & 57 deletions .github/workflows/beta-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
node-version: 16

- name: Get Version
- name: Get Package Version
run: echo "PACKAGE_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV

- name: Create Release
Expand All @@ -36,12 +36,15 @@ jobs:
const { data } = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `v${process.env.PACKAGE_VERSION}`,
name: `CSSLoader Desktop BETA v${process.env.PACKAGE_VERSION}`,
body: `${process.env.RELEASE_LOG}`,
tag_name: `beta-${process.env.PACKAGE_VERSION}`,
name: `CSSLoader Desktop Beta ${process.env.PACKAGE_VERSION}`,
body: `Download the release for your platform below`,
draft: true,
prerelease: true
});
core.setOutput("tag", `beta-${process.env.PACKAGE_VERSION}`);
return data.id
build-tauri:
Expand All @@ -59,7 +62,7 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: dev
ref: "dev"

- name: Setup Node
uses: actions/setup-node@v3
Expand Down Expand Up @@ -87,9 +90,11 @@ jobs:
with:
releaseId: ${{ needs.create-release.outputs.release_id }}
tagName: ${{ needs.create-release.outputs.tag }}
releaseBody: "Check Github for the release notes!"
releaseBody: "Download the release for your platform below"
releaseDraft: true
includeUpdaterJson: true
includeDebug: true
includeRelease: false
includeUpdaterJson: false

publish-release:
needs: [create-release, build-tauri]
Expand All @@ -102,62 +107,15 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: dev
ref: "dev"

- name: Update Release Assets
uses: actions/github-script@v6
env:
uses: ./.github/workflows/create-release-assets
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release_id: ${{ needs.create-release.outputs.release_id }}
release_tag: ${{ needs.create-release.outputs.tag }}
git_branch: "dev"
with:
script: |
const fs = require("fs");
const path = require("path");
const assets = await github.rest.repos.listReleaseAssets({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: process.env.release_id
});
const latest = assets.data.find((asset) => asset.name === "latest.json");
core.info(`latest.json assetId: ${latest.id}`);
const latestContents = (
await github.request(
'GET /repos/{owner}/{repo}/releases/assets/{asset_id}',
{
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: latest.id,
headers: {
accept: 'application/octet-stream',
},
}
)
).data;
const latestPath = path.resolve(process.cwd(), "latest.json");
fs.writeFileSync(latestPath, Buffer.from(latestContents));
const config = (prop, value) => exec.exec(`git config ${prop} "${value}"`);
const add = (file) => exec.exec(`git add ${file}`);
const commit = (message) => exec.exec(`git commit -m "${message}"`);
const push = (branch) => exec.exec(`git push origin ${branch} --follow-tags`);
const updateOrigin = (repo) => exec.exec(`git remote set-url origin ${repo}`);
core.setSecret(process.env.GITHUB_TOKEN);
updateOrigin(`https://x-access-token:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`);
config('user.name', "github-actions");
await add(".");
await commit("chore(release): updating latest.json to generated version.");
await push(process.env.git_branch);
core.info("Committed changes to latest.json complete!");

- name: Publish Release
id: publish-release
Expand Down
132 changes: 132 additions & 0 deletions .github/workflows/create-release-assets/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: "create-release-assets"
description: "Creates release assets."
author: "Tormak"
inputs:
GITHUB_TOKEN:
description: "Your GitHub token."
required: true

git_branch:
description: "The target release branch."
required: true

release_id:
description: "The target release id."
required: true

release_tag:
description: "The target release tag."
required: true

runs:
using: "composite"
steps:
- name: Update Release Assets
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
release_id: ${{ inputs.release_id }}
release_tag: ${{ inputs.release_tag }}
git_branch: ${{ inputs.git_branch }}
with:
script: |
const fs = require("fs");
const path = require("path");
async function getReleaseAssetContents(id) {
const contents = (
await github.request(
'GET /repos/{owner}/{repo}/releases/assets/{asset_id}',
{
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: id,
headers: {
accept: 'application/octet-stream',
},
}
)
).data;
return contents;
}
async function deleteReleaseAsset(id) {
await github.rest.repos.deleteReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: id
});
}
async function uploadReleaseAsset(name, contents) {
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: process.env.release_id,
name: name,
data: contents
});
}
async function setReleaseAssetName(id, newName) {
await github.rest.repos.updateReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: id,
name: newName
});
}
const versionNoV = process.env.release_tag.substring(1);
const GENERIC_NAMES = {
"windowsInstaller": `CSSLoader.Desktop_${versionNoV}.msi`,
"windowsUpdater": `CSSLoader.Desktop_${versionNoV}.msi.zip`,
"windowsUpdaterSig": `CSSLoader.Desktop_${versionNoV}.msi.zip.sig`,
}
const assets = await github.rest.repos.listReleaseAssets({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: process.env.release_id
});
const winInstaller = assets.data.find((asset) => asset.name.endsWith(".msi"));
await setReleaseAssetName(winInstaller.id, GENERIC_NAMES["windowsInstaller"]);
const winUpdater = assets.data.find((asset) => asset.name.endsWith(".msi.zip"));
await setReleaseAssetName(winUpdater.id, GENERIC_NAMES["windowsUpdater"]);
const winUpdaterSig = assets.data.find((asset) => asset.name.endsWith(".msi.zip.sig"));
await setReleaseAssetName(winUpdaterSig.id, GENERIC_NAMES["windowsUpdaterSig"]);
const latest = assets.data.find((asset) => asset.name === "latest.json");
const latestContentsBuff = Buffer.from(await getReleaseAssetContents(latest.id));
let latestContents = latestContentsBuff.toString();
await deleteReleaseAsset(latest.id);
latestContents = latestContents.replace(winUpdater.name, GENERIC_NAMES["windowsUpdater"]);
await uploadReleaseAsset("latest.json", Buffer.from(latestContents));
const latestPath = path.resolve(process.cwd(), "latest.json");
fs.writeFileSync(latestPath, Buffer.from(latestContents));
const config = (prop, value) => exec.exec(`git config ${prop} "${value}"`);
const add = (file) => exec.exec(`git add ${file}`);
const commit = (message) => exec.exec(`git commit -m "${message}"`);
const push = (branch) => exec.exec(`git push origin ${branch} --follow-tags`);
const updateOrigin = (repo) => exec.exec(`git remote set-url origin ${repo}`);
core.setSecret(process.env.GITHUB_TOKEN);
updateOrigin(`https://x-access-token:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`);
config('user.email', "[email protected]");
config('user.name', "CSSLoader Desktop Release Action");
await add(".");
await commit("chore(release): updating latest.json to generated version.");
await push(process.env.git_branch);
core.info("Committed changes to latest.json complete!");
57 changes: 57 additions & 0 deletions .github/workflows/custom-changelog/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: 'custom-changelog-action'
description: 'Generates changelogs for commitlint commits and is compatible with tauri.'
author: 'Tormak'
inputs:
github-token:
description: "Github token"
default: ${{ github.token }}
required: false

git-message:
description: "Commit message to use"
default: "chore(release): {version}"
required: false

git-user-name:
description: "The git user.name to use for the commit"
default: "Conventional Changelog Action"
required: false

git-user-email:
description: "The git user.email to use for the commit"
default: "[email protected]"
required: false

git-pull-method:
description: "The git pull method used when pulling all changes from remote"
default: "--ff-only"
required: false

git-branch:
description: "The git branch to be pushed"
default: ${{ github.ref }}
required: false

tag-prefix:
description: "Prefix that is used for the git tag"
default: "v"
required: false

git-url:
description: "Git Url"
default: "github.com"
required: false

outputs:
clean_changelog:
description: "A tidied version of the generated changelog."

tag:
description: "The tag for the new release."

version:
description: "The version for the new release."

runs:
using: 'node16'
main: 'dist/index.cjs'
56 changes: 56 additions & 0 deletions .github/workflows/custom-changelog/dist/commit.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
* {{header}}

{{~!-- commit link --}} {{#if @root.linkReferences~}}
([{{hash}}](
{{~#if @root.repository}}
{{~#if @root.host}}
{{~@root.host}}/
{{~/if}}
{{~#if @root.owner}}
{{~@root.owner}}/
{{~/if}}
{{~@root.repository}}
{{~else}}
{{~@root.repoUrl}}
{{~/if}}/
{{~@root.commit}}/{{hash}}))
{{~else}}
{{~hash}}
{{~/if}}

{{~!-- commit references --}}
{{~#if references~}}
, closes
{{~#each references}} {{#if @root.linkReferences~}}
[
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}#{{this.issue}}](
{{~#if @root.repository}}
{{~#if @root.host}}
{{~@root.host}}/
{{~/if}}
{{~#if this.repository}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}
{{~else}}
{{~#if @root.owner}}
{{~@root.owner}}/
{{~/if}}
{{~@root.repository}}
{{~/if}}
{{~else}}
{{~@root.repoUrl}}
{{~/if}}/
{{~@root.issue}}/{{this.issue}})
{{~else}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}#{{this.issue}}
{{~/if}}{{/each}}
{{~/if}}

10 changes: 10 additions & 0 deletions .github/workflows/custom-changelog/dist/footer.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{#if noteGroups}}
{{#each noteGroups}}

### {{title}}

{{#each notes}}
* {{text}}
{{/each}}
{{/each}}
{{/if}}
9 changes: 9 additions & 0 deletions .github/workflows/custom-changelog/dist/header.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## {{#if isPatch~}} <small>
{{~/if~}} {{version}}
{{~#if title}} "{{title}}"
{{~/if~}}
{{~#if date}} ({{date}})
{{~/if~}}
{{~#if isPatch~}} </small>
{{~/if}}

Loading

0 comments on commit 4b57b61

Please sign in to comment.