Skip to content

Commit

Permalink
anticipating the check for publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
j-i-l committed May 19, 2024
1 parent 7362779 commit d6e27af
Showing 1 changed file with 37 additions and 23 deletions.
60 changes: 37 additions & 23 deletions .github/workflows/publish_version_merging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,40 @@ env:
DOC_LOC: "./docs"

jobs:
build-release-content:
associated_pr:
if: ${{ github.event.pull_request.merged && startsWith(github.head_ref, 'release-') }}
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
permissions:
pull-requests: read
repository-projects: read
outputs:
published: ${{ steps.published.outputs.labeled }}
event: ${{ github.event.number }}
steps:
- name: Check if the pull request is labeled with ${{ env.LABEL_PUBLISHED }}
id: published
run: |
if $( gh pr view ${{ github.event.number }} --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
# NOTE: creating a step to check if the label is in the list of labels rather than failing below step
- name: Attempt to create label ${{ env.LABEL_PUBLISHED }}
if: ${{ steps.published.outputs.labeled == 'false' }}
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

build-release-content:
if: ${{ (needs.associated_pr.outputs.published == 'false') }}
needs:
- associated_pr
runs-on: ubuntu-latest
container:
image: ${{ vars.CONTAINER_SOURCE }}/debian/gcc/release/abn:latest
permissions:
Expand Down Expand Up @@ -45,6 +76,9 @@ jobs:
path: ${{ env.BUILD_LOC }}/abn.tar.gz

build-pkgdown-content:
if: ${{ (needs.associated_pr.outputs.published == 'false') }}
needs:
- associated_pr
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
Expand Down Expand Up @@ -78,14 +112,14 @@ jobs:

release-version:
needs:
- associated_pr
- build-release-content
- build-pckgdown-content
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
EVENT: ${{ github.event.number }} # This is either the issue or pr
permissions:
contents: write
pull-requests: write
Expand All @@ -96,22 +130,7 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
# check if the pr is labeled as published already
- name: Check if the pull request is labeled with ${{ env.LABEL_PUBLISHED }}
id: published
run: |
if $( gh pr view ${{ env.EVENT }} --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: Attempt to create label ${{ env.LABEL_PUBLISHED }}
if: ${{ steps.published.outputs.labeled == 'false' }}
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: Get the version to release
if: ${{ (steps.published.outputs.labeled == 'false') }}
id: release_version
run: |
git fetch --filter=tree:0 origin +refs/tags/*:refs/tags/*
Expand All @@ -130,12 +149,10 @@ jobs:
echo "No trace of a previous release."
fi
- name: Prepare Release note
if: ${{ (steps.published.outputs.labeled == 'false') }}
# this gets the first the changes to the previous clean tag (including manual edits)
run: |
awk '/# abn ${{ steps.release_version.outputs.version }}*/{a=1};a;/# abn ${{ steps.release_version.outputs.previous_version }}*/{exit}' NEWS.md | head -n -1 >> body.md
- name: Create tag and release
if: ${{ (steps.published.outputs.labeled == 'false') }}
run: |
gh release create ${{ steps.release_version.outputs.version }} \
--target ${{ github.event.pull_request.head.sha }} \
Expand All @@ -144,13 +161,11 @@ jobs:
--notes-file body.md \
--repo ${{ env.OWNER }}/${{ env.REPO }}
- name: Get the built package
if: ${{ steps.published.outputs.labeled == 'false' }}
uses: actions/download-artifact@v4
with:
name:
package
- name: Upload additional artifacts to the release
if: ${{ steps.published.outputs.labeled == 'false' }}
run: |
gh release upload ${{ steps.release_version.outputs.version }} \
./abn.tar.gz \
Expand All @@ -160,7 +175,6 @@ jobs:
id: deployment
uses: actions/deploy-pages@v2
- name: Adding the label ${{ env.LABEL_PUBLISHED }}
if: ${{ steps.published.outputs.labeled == 'false' }}
run: |
gh pr edit ${{ env.EVENT }} --add-label ${{ env.LABEL_PUBLISHED }} --repo ${{ env.OWNER }}/${{ env.REPO }}
gh pr edit ${{ needs.associated_pr.outputs.event }} --add-label ${{ env.LABEL_PUBLISHED }} --repo ${{ env.OWNER }}/${{ env.REPO }}
shell: bash

0 comments on commit d6e27af

Please sign in to comment.