Fixing repochat action #43
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
name: Create Release | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
create-release: | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 2 | |
- name: Get current version from package.json | |
id: current-version | |
uses: martinbeentjes/[email protected] | |
- name: Get previous version from package.json | |
id: previous-version | |
run: | | |
git checkout HEAD~1 | |
echo "::set-output name=value::$(npm pkg get version | tr -d '"')" | |
git checkout - | |
- name: Check if version has changed | |
id: version-changed | |
run: | | |
if [ "${{ steps.current-version.outputs.current-version }}" != "${{ steps.previous-version.outputs.value }}" ]; then | |
echo "::set-output name=changed::true" | |
else | |
echo "::set-output name=changed::false" | |
fi | |
- name: Extract major version | |
if: steps.version-changed.outputs.changed == 'true' | |
id: major-version | |
run: echo "::set-output name=value::$(echo ${{ steps.current-version.outputs.current-version}} | cut -d. -f1)" | |
- name: Create Release | |
if: steps.version-changed.outputs.changed == 'true' | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ steps.current-version.outputs.current-version}} | |
release_name: Release v${{ steps.current-version.outputs.current-version}} | |
draft: false | |
prerelease: false | |
- name: Create or Update Major Version Tag | |
if: steps.version-changed.outputs.changed == 'true' | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
try { | |
await github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'refs/tags/v${{ steps.major-version.outputs.value }}', | |
sha: context.sha | |
}); | |
} catch (error) { | |
if (error.status === 422) { | |
await github.rest.git.updateRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'tags/v${{ steps.major-version.outputs.value }}', | |
sha: context.sha, | |
force: true | |
}); | |
} else { | |
throw error; | |
} | |
} |