Automatically create PR for scale requests #15
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: Handle new scale issue | ||
on: | ||
issues: | ||
types: [ "opened", "edited" ] | ||
env: | ||
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/levelmeter | ||
jobs: | ||
process-issue: | ||
if: contains(github.event.issue.labels.*.name, 'automatic-scale-request') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Get Issue ID | ||
id: issue_id | ||
run: echo "id=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT | ||
- name: Parse Issue | ||
id: parse-issue | ||
uses: edumserrano/github-issue-forms-parser@v1 | ||
with: | ||
template-filepath: '.github/ISSUE_TEMPLATE/new-scale-request.yml' | ||
issue-form-body: '${{ github.event.issue.body }}' | ||
- name: Parse issue body and extract fields | ||
id: parse_fields | ||
run: | | ||
issue_body='${{ steps.parse-issue.outputs.parsed-issue }}' | ||
CONTAINER_FORM=$(echo "$issue_body" | jq -r .containerForm) | ||
LENGTH_UNIT=$(echo "$issue_body" | jq -r .lengthUnit) | ||
VOLUME_UNIT=$(echo "$issue_body" | jq -r .volumeUnit) | ||
DIAMETER=$(echo "$issue_body" | jq -r .diameter) | ||
HEIGHT=$(echo "$issue_body" | jq -r .height) | ||
MIN_VOLUME=$(echo "$issue_body" | jq -r .minVolume) | ||
MAX_VOLUME=$(echo "$issue_body" | jq -r .maxVolume) | ||
DESCRIPTION=$(echo "$issue_body" | jq -r .description) | ||
FILENAME="${CONTAINER_FORM}_${LENGTH_UNIT}_d${DIAMETER}_h${HEIGHT}_${MIN_VOLUME}-${MAX_VOLUME}${VOLUME_UNIT}_i1" | ||
DEFINITION_FILE="scales/definitions/$FILENAME.json" | ||
VECTOR_FILE="scales/svgs/$FILENAME.svg" | ||
echo "Form: $CONTAINER_FORM" | ||
echo "LengthUnit: $LENGTH_UNIT" | ||
echo "VolumeUnit: $VOLUME_UNIT" | ||
echo "Diameter: $DIAMETER" | ||
echo "Height: $HEIGHT" | ||
echo "MinVolume: $MIN_VOLUME" | ||
echo "MaxVolume: $MAX_VOLUME" | ||
echo "Description: $DESCRIPTION" | ||
echo "FileName: $FILENAME" | ||
echo "Definition: $DEFINITION_FILE" | ||
echo "SVG: $VECTOR_FILE" | ||
echo "container_form=$CONTAINER_FORM" >> $GITHUB_OUTPUT | ||
echo "length_unit=$LENGTH_UNIT" >> $GITHUB_OUTPUT | ||
echo "volume_unit=$VOLUME_UNIT" >> $GITHUB_OUTPUT | ||
echo "diameter=$DIAMETER" >> $GITHUB_OUTPUT | ||
echo "height=$HEIGHT" >> $GITHUB_OUTPUT | ||
echo "min_volume=$MIN_VOLUME" >> $GITHUB_OUTPUT | ||
echo "max_volume=$MAX_VOLUME" >> $GITHUB_OUTPUT | ||
echo "description=$DESCRIPTION" >> $GITHUB_OUTPUT | ||
echo "filename=$FILENAME" >> $GITHUB_OUTPUT | ||
echo "definition_file=$DEFINITION_FILE" >> $GITHUB_OUTPUT | ||
echo "vector_file=$VECTOR_FILE" >> $GITHUB_OUTPUT | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Create or override scale file | ||
run: | | ||
newFile="${{ steps.parse_fields.outputs.definition_file }}" | ||
cp -f ./scales/definitions/_newscale.json.template "$newFile" | ||
./scales/definitions/_apply_filename_to_json.sh "$newFile" | ||
- name: Generate scale svg | ||
run: | | ||
docker run --rm -v $(pwd):/config $IMAGE_NAME -c /config/${{ steps.parse_fields.outputs.definition_file }} | ||
- name: Configure git | ||
run: | | ||
git config --global user.name "${{ github.actor }}" | ||
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | ||
# - name: Create new branch and commit changes | ||
# run: | | ||
# BRANCH_NAME="feature/scale-request-${{ steps.issue_id.outputs.id }}" | ||
# # Run the command in a subshell to avoid exiting the script if firstcommand fails | ||
# ( | ||
# git checkout $BRANCH_NAME || git checkout -b $BRANCH_NAME | ||
# ) | ||
# ( | ||
# git add "${{ steps.parse_fields.outputs.definition_file }}" || true | ||
# git add "${{ steps.parse_fields.outputs.vector_file }}" || true | ||
# git commit -m "Add/Edit scale for scale request #${{ steps.issue_id.outputs.id }}" | ||
# ) | ||
# git push origin $BRANCH_NAME | ||
- name: Create pull request | ||
id: create_pr | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: "feature/scale-request-${{ steps.issue_id.outputs.id }}" | ||
base: main | ||
delete-branch: true | ||
title: "Scale Request #${{ steps.issue_id.outputs.id }}" | ||
body: "This PR is to handle the scale request from issue #${{ steps.issue_id.outputs.id }}" | ||
labels: automatic-scale-request | ||
commit-message: "Add/Edit scale for scale request #${{ steps.issue_id.outputs.id }}" |