Use the "publish-action" action

This commit is contained in:
MaksimZhukov 2021-05-27 14:39:14 +03:00
parent 0cfae9b3a5
commit 5529ce4143
1 changed files with 13 additions and 92 deletions

View File

@ -1,107 +1,28 @@
name: Release new action version name: Release new action version
on: on:
release:
types: [released]
workflow_dispatch: workflow_dispatch:
inputs: inputs:
TAG_NAME: TAG_NAME:
description: 'Tag name that the major tag will point to' description: 'Tag name that the major tag will point to'
required: true required: true
defaults: env:
run: TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }}
shell: pwsh
jobs: jobs:
update_tag: update_tag:
name: Update the major tag to include the ${{ github.event.inputs.TAG_NAME }} changes name: Update the major tag to include the ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} changes
environment:
name: releaseNewActionVersion
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: write
steps: steps:
- name: Check if the ${{ github.event.inputs.TAG_NAME }} tag exists - name: Update the ${{ env.TAG_NAME }} tag
id: validate-source-tag
uses: actions/github-script@v3
with:
script: |
try{
const sourceTag = await github.git.getRef({
...context.repo,
ref: "tags/${{ github.event.inputs.TAG_NAME }}"
});
const sourceTagSHA = sourceTag.data.object.sha
core.setOutput('source-tag-sha', sourceTagSHA)
} catch (error) {
core.setFailed(error.message);
}
- name: Validate the ${{ github.event.inputs.TAG_NAME }} tag
run: |
$versionToValidate = "${{ github.event.inputs.TAG_NAME }}".TrimStart("v")
if ($versionToValidate.Split(".").length -lt 3) {
echo "::error::The version specified in the ${{ github.event.inputs.TAG_NAME }} tag is short. You have to specify the full version, for example: 'v1.0.0'"
exit 1
}
[Semver]$semanticVersion = $null
if(-not [Semver]::TryParse($versionToValidate, [ref]$semanticVersion)) {
echo "::error::The ${{ github.event.inputs.TAG_NAME }} tag contains unsupported type of version. Only semantic versioning specification is acceptable"
exit 1
}
if ($semanticVersion.PreReleaseLabel -or $semanticVersion.BuildLabel) {
echo "::error::You have to specify only stable version to update the major tag"
exit 1
}
- name: Update the major tag
id: update-major-tag id: update-major-tag
uses: actions/github-script@v3 uses: actions/publish-action@v0.1.0
with: with:
script: | source-tag: ${{ env.TAG_NAME }}
try{ slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
const majorTag = "${{ github.event.inputs.TAG_NAME }}".split(".")[0];
core.setOutput('major-tag', majorTag)
const refName = `tags/${majorTag}`;
const { data: foundRefs } = await github.git.listMatchingRefs({
...context.repo,
ref: refName
});
const matchingRef = foundRefs.find( refObj => refObj.ref.endsWith(refName) );
if (matchingRef !== undefined) {
core.info(`Updating the ${majorTag} tag to point to the ${{ github.event.inputs.TAG_NAME }} tag`);
await github.git.updateRef({
...context.repo,
ref: refName,
sha: '${{ steps.validate-source-tag.outputs.source-tag-sha }}',
force: true
});
} else {
core.info(`Creating the ${majorTag} tag from the ${{ github.event.inputs.TAG_NAME }} tag`);
await github.git.createRef({
...context.repo,
ref: `refs/${refName}`,
sha: '${{ steps.validate-source-tag.outputs.source-tag-sha }}'
});
}
} catch (error) {
core.setFailed(error.message);
}
- name: Send slack message
if: failure()
run: |
curl `
-X POST `
-H 'Content-type: application/json' `
--data '{\"text\":\"Failed to update a major tag for the ${{ github.repository }} action\"}' `
${{ secrets.SLACK }}
- name: Send slack message
if: success()
run: |
curl `
-X POST `
-H 'Content-type: application/json' `
--data '{\"text\":\"The ${{ steps.update-major-tag.outputs.major-tag }} tag has been successfully updated for the ${{ github.repository }} action to include changes from the ${{ github.event.inputs.TAG_NAME }}\"}' `
${{ secrets.SLACK }}