-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
8 additions
and
146 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,153 +1,15 @@ | ||
name: Create Release for tag | ||
name: Call Create Release for tag Workflow | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
provide_changed_packages: | ||
# see json juggling: https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#example-6 | ||
# see https://stackoverflow.com/a/62953566/1348344 | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Set Environment | ||
run: | | ||
echo "BUILD_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV | ||
- uses: actions/checkout@v3 | ||
|
||
# load current composer.lock | ||
- id: currentLock | ||
name: Gather latest package information | ||
run: | | ||
OUT=$(jq --slurp '[.[].packages[] | select(.name | contains("ezsystems") or contains("ibexa")) | [.name, .version] | { name: (.[0]), version: .[1] }]' composer.lock) | ||
echo "lock=$( echo "$OUT" | sed ':a;N;$!ba;s/\n//g' )" >> $GITHUB_OUTPUT | ||
- name: Get previous last full release | ||
id: prevfull | ||
run: | | ||
OUT=$(hub api /repos/${{ github.repository }}/releases | jq -r '[.[] | select(.tag_name | test("^(?!.*alpha|.*beta|.*rc).*$")) | .tag_name] | sort_by(.) | last') | ||
echo "tag=$( echo "$OUT" )" >> $GITHUB_OUTPUT | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Get previous release tag based on type | ||
id: prevrelease | ||
uses: ibexa/version-logic-action@master | ||
with: | ||
currentTag: ${{ env.BUILD_TAG }} | ||
prevFullTag: ${{ steps.prevfull.outputs.tag }} | ||
|
||
# checkout previous tag | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ steps.prevrelease.outputs.previousTag }} | ||
|
||
# load previous composer.lock | ||
- id: previousLock | ||
name: Gather previous package information | ||
run: | | ||
OUT=$(jq --slurp '[.[].packages[] | select(.name | contains("ezsystems") or contains("ibexa")) | [.name, .version] | { name: (.[0]), version: .[1] }]' composer.lock) | ||
echo "lock=$( echo "$OUT" | sed ':a;N;$!ba;s/\n//g' )" >> $GITHUB_OUTPUT | ||
# do some magic comparing those outputs | ||
- id: output_data | ||
name: Do comparison and output JSON with changes | ||
run: | | ||
FILE1=$(mktemp) | ||
FILE2=$(mktemp) | ||
cat > $FILE1 <<'EOF' | ||
${{ steps.previousLock.outputs.lock }} | ||
EOF | ||
cat > $FILE2 <<'EOF' | ||
${{ steps.currentLock.outputs.lock }} | ||
EOF | ||
# Get only changed packages and sort versions in ascending order | ||
# Step 1: Merge composer.json from two versions, grouping by .name | ||
# Step 2: Take .versions key and remove duplicate versions (means this bundle did not change) | ||
# Step 3: Select only those bundles that have more than 1 version in .versions | ||
# Step 4: Sort versions | ||
# Step 5: (outer brackets) Wrap that into JSON list of objects | ||
# Note: zzzz is added as an additional suffix to properly sort out alpha/beta/etc pre-releases (v2.5.1-alphazzzz < v2.5.1zzzz) | ||
OUT=$(jq -s 'flatten | group_by(.name)' $FILE1 $FILE2 | jq -s '[ .[][] | {name: (.[0].name), versions: [ .[0].version, .[1].version ] | unique} | select(.versions | length > 1) ] | .[].versions |= sort_by( . + "zzzz" | [scan("[0-9]+|[a-z]+")] | map(tonumber? // .) )') | ||
echo "matrix=$( echo "$OUT" | sed ':a;N;$!ba;s/\n//g' )" >> $GITHUB_OUTPUT | ||
# this step is needed, so the output gets to the next defined job | ||
outputs: | ||
matrix: ${{ steps.output_data.outputs.matrix }} | ||
|
||
get_package_changelogs: | ||
needs: provide_changed_packages | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Set Environment | ||
run: | | ||
echo "BUILD_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV | ||
- name: Generate token | ||
id: generate_token | ||
uses: tibdex/github-app-token@v1 | ||
with: | ||
app_id: ${{ secrets.AUTOMATION_CLIENT_ID }} | ||
installation_id: ${{ secrets.AUTOMATION_CLIENT_INSTALLATION }} | ||
private_key: ${{ secrets.AUTOMATION_CLIENT_SECRET }} | ||
- name: Get previous release tag based on type | ||
id: prevrelease | ||
uses: ibexa/version-logic-action@master | ||
with: | ||
currentTag: ${{ env.BUILD_TAG }} | ||
|
||
- name: Checkout Generator | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: ibexa/changelog-generator-action | ||
ref: v2 | ||
|
||
- name: Setup Python environment | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install pygithub & jira | ||
run: | | ||
pip install pygithub jira github-action-utils | ||
- name: Run generator in a loop | ||
id: generator | ||
env: | ||
INPUT_GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} | ||
INPUT_JIRA_TOKEN: ${{ secrets.JIRA_TOKEN }} | ||
run: | | ||
cat > input.json <<'EOF' | ||
${{ needs.provide_changed_packages.outputs.matrix }} | ||
EOF | ||
export INPUT_BARE=True | ||
echo "${{ github.repository }} ${{ env.BUILD_TAG }} change log" >> generator_output | ||
echo "" >> generator_output | ||
echo "Changes since ${{ steps.prevrelease.outputs.previousTag }}" >> generator_output | ||
echo "" >> generator_output | ||
jq -c '.[]' input.json | while read i; do | ||
export GITHUB_REPOSITORY=$(jq -r '.name' <<< "$i") | ||
export INPUT_PREVIOUSTAG=$(jq -r '.versions[0]' <<< "$i") | ||
export INPUT_CURRENTTAG=$(jq -r '.versions[1]' <<< "$i") | ||
echo Running against $GITHUB_REPOSITORY | ||
echo -n "## " >> generator_output | ||
python main.py >> generator_output | ||
echo '' >> generator_output | ||
done | ||
echo "CHANGELOG_OUTPUT<<EOF" >> $GITHUB_ENV | ||
echo "$(cat generator_output)" >> $GITHUB_ENV | ||
echo "EOF" >> $GITHUB_ENV | ||
- name: Create Release | ||
id: create_release | ||
uses: zendesk/action-create-release@v1 | ||
with: | ||
tag_name: ${{ env.BUILD_TAG }} | ||
body: | | ||
${{ env.CHANGELOG_OUTPUT }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Archive markdown | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: changelogs | ||
path: generator_output | ||
create_release_for_tag: | ||
uses: ibexa/gh-workflows/.github/workflows/release.yml@main | ||
secrets: | ||
AUTOMATION_CLIENT_ID: ${{ secrets.AUTOMATION_CLIENT_ID }} | ||
AUTOMATION_CLIENT_INSTALLATION: ${{ secrets.AUTOMATION_CLIENT_INSTALLATION }} | ||
AUTOMATION_CLIENT_SECRET: ${{ secrets.AUTOMATION_CLIENT_SECRET }} | ||
JIRA_TOKEN: ${{ secrets.JIRA_TOKEN }} |