Skip to content

Commit

Permalink
Merge pull request #28 from release-kit/chore/update-release-workflow
Browse files Browse the repository at this point in the history
Update release workflow
  • Loading branch information
Evgeny Zakharov authored May 28, 2023
2 parents d18fd86 + 73092b8 commit 8b8778d
Showing 1 changed file with 11 additions and 59 deletions.
70 changes: 11 additions & 59 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,26 @@ on:
types: [published]

jobs:
get-meta:
runs-on: ubuntu-latest
steps:
- name: Checkout to tag
uses: actions/checkout@v3
with:
ref: ${{ github.event.release.tag_name }}
fetch-depth: 0

- name: Parse semver string
id: version
uses: release-kit/semver@v1

- name: Check branch existence
id: branch-exists
run: echo "::set-output name=flag::$(git ls-remote --heads ${{ github.server_url }}/${{ github.repository }} ${{ needs.get-meta.outputs.branch }} | wc -l)"

outputs:
tag: ${{ github.event.release.tag_name }}
major: ${{ steps.version.outputs.major }}
branch: ${{ steps.version.outputs.prerelease != null && 'release/${{ steps.version.outputs.prerelease }}' || 'release/latest' }}
branch-exists: ${{ steps.branch-exists.outputs.flag == '1' }}

sync-latest:
release:
runs-on: ubuntu-latest
needs: get-meta
if: needs.get-meta.outputs.branch == 'release/latest'
steps:
- name: Setup git
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "<>"
- name: Checkout
- name: Checkout to released tag
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Create branch
if: ${{ !needs.get-meta.outputs.branch-exists }}
run: |
git checkout -b ${{ needs.get-meta.outputs.branch }}
git push -u origin ${{ needs.get-meta.outputs.branch }}

- name: Checkout branch
if: ${{ needs.get-meta.outputs.branch-exists }}
run: git checkout ${{ needs.get-meta.outputs.branch }}
- name: Parse version from tag
id: version
uses: release-kit/semver@v2

- name: Override branch using tag HEAD
run: git reset --hard ${{ needs.get-meta.outputs.tag }}
- name: Force update remote latest release branch
run: git push origin ${{ github.event.release.tag_name }}:refs/heads/release/latest -f

- name: Update major tag
run: git tag -f v${{ needs.get-meta.outputs.major }}
- name: Force update remote major release branch
run: git push origin ${{ github.event.release.tag_name }}:refs/heads/release/${{ steps.version.outputs.major }} -f

- name: Push to protected branch
uses: CasperWA/push-protected@v2
env:
TOKEN: ${{ secrets.FULL_ACCESS_GITHUB_TOKEN }}
if: ${{ env.TOKEN != '' }}
with:
token: ${{ secrets.FULL_ACCESS_GITHUB_TOKEN }}
branch: ${{ needs.get-meta.outputs.branch }}
tags: true
force: true
unprotect_reviews: true

- name: Push to unprotected branch
env:
TOKEN: ${{ secrets.FULL_ACCESS_GITHUB_TOKEN }}
if: ${{ env.TOKEN == '' }}
run: git push --tags --force
- name: Force update major release tag
run: git push origin ${{ github.event.release.tag_name }}:refs/tags/v${{ steps.version.outputs.major }} -f

0 comments on commit 8b8778d

Please sign in to comment.