Skip to content

Commit

Permalink
better starting condition for forced release
Browse files Browse the repository at this point in the history
  • Loading branch information
j-i-l committed May 17, 2024
1 parent 5029633 commit 9cc45c7
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions .github/workflows/publish_version_enforce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,34 @@ env:
DOC_LOC: "./docs"

jobs:
# NOTE: This workflow only runs if a release- branch has an open pull request
associated_pr:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
permissions:
contents: write
pull-requests: write
repository-projects: write
outputs:
event: ${{ steps.get_pr.outputs.pr }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # NOTE: This might be needed to assert that we get the full history
# for the changelog.
# get the related pull request
- name: Determine associated Pull request
id: get_pr
run: |
echo "PR=`echo $(gh pr list --repo ${{ env.OWNER }}/${{ env.REPO }} --json 'number,headRefName'|jq --arg NAME ${{ github.ref_name }} '.[] | select(.headRefName | contains($NAME)) | .number')`" >> $GITHUB_OUTPUT
build-release-content:
if: ${{ github.ref_name == startsWith('release-') }} # only run on release- branches
runs-on: ubuntu-latest
needs:
- associated_pr
container:
image: ${{ vars.CONTAINER_SOURCE }}/debian/gcc/release/abn:latest
permissions:
Expand Down Expand Up @@ -63,7 +88,9 @@ jobs:

release-version:
# NOTE: Currently this workflow only runs if a release- branch has an open pull request
needs: build-release-content
needs:
- build-release-content
- associated_pr
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -78,36 +105,30 @@ jobs:
with:
fetch-depth: 0 # NOTE: This might be needed to assert that we get the full history
# for the changelog.
# get the related pull request
- name: Determine associated Pull request
id: get_pr
run: |
echo "PR=`echo $(gh pr list --repo ${{ env.OWNER }}/${{ env.REPO }} --json 'number,headRefName'|jq --arg NAME ${{ github.ref_name }} '.[] | select(.headRefName | contains($NAME)) | .number')`" >> $GITHUB_OUTPUT
- name: Attempt to create label ${{ env.LABEL_PUBLISHED }}
if: ${{ steps.get_pr.outputs.pr }}
if: ${{ needs.associated_pr.outputs.pr }}
id: present_label
run: |
gh label create ${{ env.LABEL_PUBLISHED }} --repo ${{ env.OWNER }}/${{ env.REPO }}
continue-on-error: true # make sure the next steps run also on failure
- name: Check if the pull request is labeled with ${{ env.LABEL_PUBLISHED }} # 2
if: ${{ steps.get_pr.outputs.pr }}
id: published
run: |
if $( gh pr view ${{ steps.get_pr.outputs.pr }} --repo ${{ env.OWNER }}/${{ env.REPO }} --json "labels" --jq ".[].[].name" | grep --quiet ${{ env.LABEL_PUBLISHED }}); then
if $( gh pr view ${{ needs.associated_pr.outputs.pr }} --repo ${{ env.OWNER }}/${{ env.REPO }} --json "labels" --jq ".[].[].name" | grep --quiet ${{ env.LABEL_PUBLISHED }}); then
echo "LABELED=true" >> $GITHUB_OUTPUT
else
echo "LABELED=false" >> $GITHUB_OUTPUT
fi
- name: Get the version to release # 2
if: ${{ (steps.published.outputs.labeled == 'false') && steps.get_pr.outputs.pr }}
if: ${{ (steps.published.outputs.labeled == 'false') }}
id: release_version
run: |
git fetch --filter=tree:0 origin +refs/tags/*:refs/tags/*
echo "VERSION=$(echo ${{ github.ref_name }}|grep -Eo '[0-9]+.[0-9]+.[0-9]+')" >> $GITHUB_OUTPUT
echo "PREVIOUS_VERSION=`echo $(git tag --list | grep -E '[0-9]+.[0-9]+.[0-9]+$' | tail -n1)`" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Remove previous releases of the target tag, if existing # 2
if: ${{ (steps.published.outputs.labeled == 'false') && steps.get_pr.outputs.pr }}
if: ${{ (steps.published.outputs.labeled == 'false') }}
run: |
if script -q -e -c "gh release view ${{ steps.release_version.outputs.version }} --repo ${{ env.OWNER }}/${{ env.REPO }}"; then
# removing previous release along with associated tag
Expand All @@ -119,13 +140,13 @@ jobs:
echo "No trace of a previous release."
fi
- name: Prepare Release note # 2
if: ${{ (steps.published.outputs.labeled == 'false') && steps.get_pr.outputs.pr }}
if: ${{ (steps.published.outputs.labeled == 'false') }}
# this gets the first the changes to the previous clean tag (including manual edits)
run: |
awk '/<a name="${{ steps.release_version.outputs.version }}".*/{a=1};a;/<a name="${{ steps.release_version.outputs.previous_version }}"*/{exit}' NEWS.md | head -n -1 >> body.md
awk '/<a name="${{ steps.release_version.outputs.version }}".*/{a=1};a;/<a name="${{ needs.associated_pr.outputs.previous_version }}"*/{exit}' NEWS.md | head -n -1 >> body.md
cat body.md
- name: Create tag and release # 2
if: ${{ (steps.published.outputs.labeled == 'false') && steps.get_pr.outputs.pr }}
if: ${{ (steps.published.outputs.labeled == 'false') }}
run: |
echo $GITHUB_SHA
gh release create ${{ steps.release_version.outputs.version }} \
Expand All @@ -135,9 +156,9 @@ jobs:
--notes-file body.md \
--repo ${{ env.OWNER }}/${{ env.REPO }} \
- name: Adding the label ${{ env.LABEL_PUBLISHED }} # 2
if: ${{ (steps.published.outputs.labeled == 'false') && steps.get_pr.outputs.pr }}
if: ${{ (steps.published.outputs.labeled == 'false') }}
run: |
gh pr edit ${{ steps.get_pr.outputs.pr }} --add-label ${{ env.LABEL_PUBLISHED }} --repo ${{ env.OWNER }}/${{ env.REPO }}
gh pr edit ${{ needs.associated_pr.outputs.pr }} --add-label ${{ env.LABEL_PUBLISHED }} --repo ${{ env.OWNER }}/${{ env.REPO }}
shell: bash
- name: Get the built package
uses: actions/download-artifact@v4
Expand Down

0 comments on commit 9cc45c7

Please sign in to comment.