Project labelling #533
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: Project labelling | |
on: | |
project_card: | |
types: [created, moved, deleted] | |
jobs: | |
process-project: | |
name: Add/remove the project label and set the matrix variable | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.setMatrixData.outputs.matrix }} | |
statusLabel: ${{ steps.setStatusLabel.outputs.statusLabel }} | |
steps: | |
- name: Fetch project data | |
run: | | |
echo 'PROJECT_DATA<<EOF' >> $GITHUB_ENV | |
curl --request GET --url '${{ github.event.project_card.project_url }}' --header 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' >> $GITHUB_ENV | |
echo 'EOF' >> $GITHUB_ENV | |
### Add or remove the project label ### | |
- name: Add the project label | |
uses: andymckay/labeler@master | |
if: ${{ contains(github.event.action, 'created') || contains(github.event.action, 'moved') }} | |
with: | |
add-labels: "Project: ${{ fromJSON(env.PROJECT_DATA).name }}" | |
- name: Remove the project label | |
uses: andymckay/labeler@master | |
if: ${{ contains(github.event.action, 'deleted') }} | |
with: | |
remove-labels: "Project: ${{ fromJSON(env.PROJECT_DATA).name }}" | |
### Fetch project columns ### | |
- name: Fetch all columns | |
run: | | |
echo 'ALL_COLUMNS_DATA<<EOF' >> $GITHUB_ENV | |
curl --request GET --url '${{ fromJSON(env.PROJECT_DATA).columns_url }}' --header 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' | jq --compact-output '["Status: " + .[].name]' >> $GITHUB_ENV | |
echo 'EOF' >> $GITHUB_ENV | |
- name: Fetch column info | |
run: | | |
echo 'COLUMN_DATA<<EOF' >> $GITHUB_ENV | |
curl --request GET --url '${{ github.event.project_card.column_url }}' --header 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' >> $GITHUB_ENV | |
echo 'EOF' >> $GITHUB_ENV | |
- uses: actions/github-script@v6 | |
id: setMatrixData | |
with: | |
result-encoding: string | |
script: | | |
const columnData = JSON.parse(process.env.COLUMN_DATA) | |
const allColumnsData = JSON.parse(process.env.ALL_COLUMNS_DATA) | |
const matrix = allColumnsData.filter((label) => { | |
return label !== `Status: ${columnData.name}` | |
}); | |
core.setOutput('matrix', matrix) | |
- name: Set the status label | |
id: setStatusLabel | |
run: | | |
echo "statusLabel=${{ fromJSON(env.COLUMN_DATA).name }}" >> $GITHUB_OUTPUT | |
remove-labels: | |
runs-on: ubuntu-latest | |
needs: process-project | |
if: ${{ contains(github.event.action, 'deleted') || contains(github.event.action, 'moved') }} | |
strategy: | |
matrix: | |
label: ${{fromJson(needs.process-project.outputs.matrix)}} | |
steps: | |
- name: Remove the status label | |
uses: andymckay/labeler@master | |
with: | |
remove-labels: ${{ matrix.label }} | |
add-labels: | |
runs-on: ubuntu-latest | |
needs: | |
- process-project | |
- remove-labels | |
if: ${{ contains(github.event.action, 'created') || contains(github.event.action, 'moved') }} | |
steps: | |
- name: Add the status label | |
uses: andymckay/labeler@master | |
with: | |
add-labels: "Status: ${{ needs.process-project.outputs.statusLabel }}" | |