Skip to content

Release

Release #33

Workflow file for this run

name: Release
on:
workflow_run:
workflows:
- Tagging
branches:
- main
types:
- completed
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
if: ${{ contains(github.ref, 'main') }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Fetch remote tags
run: git fetch origin +refs/tags/*:refs/tags/*
- name: Set Tag Value
run: |
export DATE=v$(echo `date +'%Y.%m'`)
echo "DATE=${DATE}" >> $GITHUB_ENV
echo "TAG=$(echo `git tag -l ${DATE}`)" >> $GITHUB_ENV
echo "CHANGELOG=`git log --oneline $(git describe --tags @ --abbrev=0 @^ | head -n 1)..@ --pretty=format:"%h %an %s"`" >> $GITHUB_ENV
- name: Create Release
uses: actions/github-script@v7
id: release
if: ${{ env.TAG }}
with:
github-token: ${{ github.token }}
result-encoding: string
script: |
const { repo: { owner, repo }, sha } = context;
const tag = process.env.DATE;
let release_id = 0;
try {
const release = await github.rest.repos.createRelease({
owner, repo,
tag_name: tag,
title: tag,
name: tag,
body: "${{ env.CHANGELOG }}",
draft: false,
make_latest: "true",
target_commitish: sha
});
release_id = release.data.id;
} catch (e) {
let latest;
if (e.status == 422) { // Release alredy exists
latest = await github.rest.repos.getLatestRelease({
owner, repo
});
}
release_id = latest.data.id;
}
return release_id
- name: Upload Release Assets
uses: actions/github-script@v7
if: ${{ steps.release.outputs.result }}
with:
github-token: ${{ github.token }}
script: |
const { repo: { owner, repo }, sha } = context;
const fs = require('fs').promises;
try {
let asset_ids = await github.rest.repos.listReleaseAssets({
owner, repo,
release_id: ${{ steps.release.outputs.result }}
})
for (let asset of asset_ids.data) {
await github.rest.repos.deleteReleaseAsset({
owner, repo,
asset_id: asset.id
});
}
} catch (e) {
console.log(e.status);
}