Skip to content

Workflow file for this run

name: Automatically handle new library submissions
env:
# See: https://github.com/actions/setup-python/tree/main#available-versions-of-python
PYTHON_VERSION: "3.12"
LISTFILE_LOC: "${{ github.workspace }}/output_files/list_file.txt"
ACCEPTED_REPOSITORIES_LOC: "${{ github.workspace }}/output_files/accepted_repositories.txt"
on:
pull_request_target:
types:
- opened
- ready_for_review
- synchronize
jobs:
diff:
if: >
(
github.event_name == 'pull_request_target' &&
github.event.pull_request.draft == false
)
runs-on: ubuntu-latest
outputs:
artifact: ${{ steps.configuration.outputs.artifact }}
path: ${{ steps.configuration.outputs.path }}
filename: ${{ steps.configuration.outputs.filename }}
head: ${{ steps.head.outputs.head }}
env:
# See: https://docs.github.com/rest/reference/pulls#custom-media-types-for-pull-requests
DIFF_IDENTIFIER: diff
JSON_IDENTIFIER: raw+json
steps:
- name: Set configuration outputs
id: configuration
run: |
echo -E "artifact=diff" >> $GITHUB_OUTPUT
echo -E "path=${{ runner.temp }}" >> $GITHUB_OUTPUT
echo -E "filename=${{ env.DIFF_IDENTIFIER }}" >> $GITHUB_OUTPUT
- name: Get PR data
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
parallel \
' \
curl \
--fail \
--output "${{ steps.configuration.outputs.path }}/{}" \
--header "Authorization: token $GITHUB_TOKEN" \
--header "Accept: application/vnd.github.v3.{}" \
https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/pulls/${{ github.event.pull_request.number }}
' \
::: \
${{ env.DIFF_IDENTIFIER }} \
${{ env.JSON_IDENTIFIER }}
- name: Get head SHA of diff
id: head
run: |
echo -E "head=$(jq -c .head.sha "${{ steps.configuration.outputs.path }}/${{ env.JSON_IDENTIFIER }}")" >> $GITHUB_OUTPUT
- name: Upload diff file to workflow artifact
uses: actions/upload-artifact@v3
with:
path: ${{ steps.configuration.outputs.path }}/${{ steps.configuration.outputs.filename }}
name: ${{ steps.configuration.outputs.artifact }}
parse:
needs:
- diff
runs-on: ubuntu-latest
outputs:
type: ${{ steps.parse-request.outputs.type }}
submissions: ${{ steps.parse-request.outputs.submissions }}
index-entry: ${{ steps.parse-request.outputs.index-entry }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: false
virtualenvs-in-project: false
- name: Install Libversion
run: |
. /etc/lsb-release
echo "deb [trusted=yes] https://download.opensuse.org/repositories/home:/t-paul:/libversion/xUbuntu_$DISTRIB_RELEASE/ ./" | sudo tee /etc/apt/sources.list.d/libversion.list
sudo apt update
sudo apt install libversion3-dev
- name: Install Dependencies
run: |
poetry install --directory="${{ github.workspace }}/olman-remote"
- name: Download diff
uses: actions/download-artifact@v3
with:
path: ${{ needs.diff.outputs.path }}
name: ${{ needs.diff.outputs.artifact }}
- name: Parse request
id: parse-request
run: |
python${{ env.PYTHON_VERSION }} -u "${{ github.workspace }}/olman-remote/pr_parser.py" \
--diffpath="${{ needs.diff.outputs.path }}/${{ needs.diff.outputs.filename }}" \
--listpath="${{ env.LISTFILE_LOC }}" \
-v > ${{ runner.temp }}/pr_parser_output.json
echo -E "type=$(cat ${{ runner.temp }}/pr_parser_output.json | jq --unbuffered -r -c '.type')" >> $GITHUB_OUTPUT
echo -E "submissions=$(cat ${{ runner.temp }}/pr_parser_output.json | jq --unbuffered -c '.submissions')" >> $GITHUB_OUTPUT
echo -E "index-entry=$(cat ${{ runner.temp }}/pr_parser_output.json | jq --unbuffered -c '.index_entry')" >> $GITHUB_OUTPUT
cat ${{ runner.temp }}/pr_parser_output.json
merge:
needs:
- diff
- parse
if: >
needs.parse.outputs.type == 'addition'
runs-on: ubuntu-latest
outputs:
pass: ${{ steps.merge.outcome == 'success' }}
status: ${{ steps.merge.outputs.status }}
steps:
- name: Approve pull request
uses: octokit/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
route: POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews
owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
pull_number: ${{ github.event.pull_request.number }}
event: APPROVE
- name: Merge pull request
id: merge
continue-on-error: true # Error in some situations (e.g., merge conflict) is expected
uses: octokit/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
route: PUT /repos/{owner}/{repo}/pulls/{pull_number}/merge
owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
pull_number: ${{ github.event.pull_request.number }}
sha: ${{ needs.diff.outputs.head }}
merge_method: squash
update:
needs:
- diff
- parse
- merge
if: >
needs.parse.outputs.type == 'addition'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Add index source file entry for submissions
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHubBot OpenSCAD"
git pull
git reset --hard origin/main
echo -e ${{ needs.parse.outputs.index-entry }} >> "${{ env.ACCEPTED_REPOSITORIES_LOC }}"
git add --update "${{ env.ACCEPTED_REPOSITORIES_LOC }}"
git commit -m "Add submission ${{ github.event.pull_request.number }} -- ${{ github.event.repository.html_url }}/pull/${{ github.event.pull_request.number }}"
git push
- name: Comment that submission was accepted
uses: octokit/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
route: POST /repos/{owner}/{repo}/issues/{issue_number}/comments
owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
issue_number: ${{ github.event.pull_request.number }}
body: |
|
Your submission has now been accepted! Thanks for your contribution to the OpenSCAD Library Manager index.