Skip to content

Commit

Permalink
Merge pull request #567 from MAKENTNU/dev
Browse files Browse the repository at this point in the history
Deployment
  • Loading branch information
ddabble authored Oct 28, 2022
2 parents 9016a87 + 6333885 commit 6374f2f
Show file tree
Hide file tree
Showing 27 changed files with 671 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ ij_markdown_insert_quote_arrows_on_wrap = true
ij_markdown_keep_indents_on_empty_lines = false
ij_markdown_keep_line_breaks_inside_text_blocks = true
ij_markdown_max_lines_around_block_elements = 0
ij_markdown_max_lines_around_header = 0
ij_markdown_max_lines_around_header = 1
ij_markdown_max_lines_between_paragraphs = 1
ij_markdown_min_lines_around_block_elements = 1
ij_markdown_min_lines_around_header = 3
Expand Down
16 changes: 8 additions & 8 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
## Proposed changes
_Describe the changes you've made_

<!-- Describe the changes you've made -->


## Areas to review closely
_Refer to areas of the changed code where you would like reviewers to take a closer look_

<!-- Refer to areas of the changed code where you would like reviewers to take a closer look -->


## Checklist

_(If any of the points are not relevant, mark them as checked)_

- [ ] Created tests that fail without the changes, if relevant/possible
- [ ] Made sure that your code conforms to [the code style guides](https://github.com/MAKENTNU/web/blob/main/CONTRIBUTING.md#code-style-guides)
and that any [common code smells](https://github.com/MAKENTNU/web/blob/main/CONTRIBUTING.md#code-review-guideline-code-smells) have been addressed
- (It's not intended that you read through this whole document, but that you get yourself an overview over its contents,
and that you keep it in mind while taking a second look at your code before opening a pull request)
- [ ] Made sure that your code conforms to [the code style guides](https://github.com/MAKENTNU/web/blob/main/CONTRIBUTING.md#code-style-guides) and that any [common code smells](https://github.com/MAKENTNU/web/blob/main/CONTRIBUTING.md#code-review-guideline-code-smells) have been addressed
- (It's not intended that you read through this whole document, but that you get yourself an overview over its contents, and that you keep it in mind while taking a second look at your code before opening a pull request)
- [ ] Added sufficient documentation - e.g. as docstrings or in the [README](https://github.com/MAKENTNU/web/blob/main/README.md), if suitable
- [ ] Added your changes to the ["Unreleased" section of the changelog](https://github.com/MAKENTNU/web/blob/main/CHANGELOG.md#unreleased) -
mainly the changes that are of particular interest to users and/or developers, if any
- [ ] Added your changes to the ["Unreleased" section of the changelog](https://github.com/MAKENTNU/web/blob/main/CHANGELOG.md#unreleased) - mainly the changes that are of particular interest to users and/or developers, if any
- [ ] Added a "Deployment notes" section above, if anything out of the ordinary should be done when deploying these changes to the server
174 changes: 174 additions & 0 deletions .github/workflows/_reusable_add-content-to-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# This is a reusable workflow; see https://docs.github.com/en/actions/using-workflows/reusing-workflows

name: Add content to project

on:
workflow_call:
inputs:
content_id:
description: "The ID of an issue or a PR, to be added to this repo's GitHub project"
required: true
type: string
status_field_value_name:
description: "The name of one of the values of the project's (single select) 'Status' field, to set for the added project item"
required: true
type: string

jobs:
add_content:
runs-on: ubuntu-latest
# Code based on https://docs.github.com/en/issues/planning-and-tracking-with-projects/automating-your-project/automating-projects-using-actions#example-workflow-authenticating-with-a-github-app
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@f717b5ecd4534d3c4df4ce9b5c1c2214f0f7cd06
with:
app_id: ${{ secrets.MAKE_BOT_APP_ID }}
private_key: ${{ secrets.MAKE_BOT_APP_PEM }}

- name: Get project data
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
ORGANIZATION: MAKENTNU
PROJECT_NUMBER: 1
STATUS_FIELD_VALUE_NAME: ${{ inputs.status_field_value_name }}
run: |
gh api graphql -f query='
query ($org: String!, $number: Int!) {
organization(login: $org) {
projectV2(number: $number) {
id
fields(first: 20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -f org="$ORGANIZATION" -F number="$PROJECT_NUMBER" > project_data.json
{
# The ID of this repo's GitHub project
echo "PROJECT_ID=$(jq -r '.data.organization.projectV2.id' project_data.json)"
# The ID of the project's 'Date posted' field
echo "DATE_FIELD_ID=$(jq -r '.data.organization.projectV2.fields.nodes[] | select(.name=="Date posted") | .id' project_data.json)"
# The ID of the project's 'Status' field
echo "STATUS_FIELD_ID=$(jq -r '.data.organization.projectV2.fields.nodes[] | select(.name=="Status") | .id' project_data.json)"
# The ID of one of the values of the project's (single select) 'Status' field, with name `inputs.status_field_value_name`
echo "STATUS_FIELD_VALUE_ID=$(jq --arg STATUS_NAME "$STATUS_FIELD_VALUE_NAME" -r '.data.organization.projectV2.fields.nodes[] | select(.name=="Status") | .options[] | select(.name==$STATUS_NAME) | .id' project_data.json)"
} >> "$GITHUB_ENV"
- name: Add content to project
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
CONTENT_ID: ${{ inputs.content_id }}
run: |
item_id="$( gh api graphql -f query='
mutation ($project: ID!, $content: ID!) {
addProjectV2ItemById(input: {projectId: $project, contentId: $content}) {
item {
id
}
}
}' -f project="$PROJECT_ID" -f content="$CONTENT_ID" --jq '.data.addProjectV2ItemById.item.id' )"
# The ID of the project item (representing an issue or a PR with ID `inputs.content_id`), which was either added or already existed
echo "ITEM_ID=$item_id" >> "$GITHUB_ENV"
- name: Get project item data
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
gh api graphql -f query='
query ($itemId: ID!) {
node(id: $itemId) {
... on ProjectV2Item {
fieldValues(first: 20) {
nodes {
... on ProjectV2ItemFieldSingleSelectValue {
name
field {
... on ProjectV2SingleSelectField {
id
}
}
}
... on ProjectV2ItemFieldDateValue {
date
field {
... on ProjectV2Field {
id
}
}
}
}
}
}
}
}' -f itemId="$ITEM_ID" > project_item_data.json
{
# The value of the project item's 'Date posted' field (with ID `env.DATE_FIELD_ID`)
echo "DATE_FIELD_VALUE=$(jq --arg FIELD_ID "$DATE_FIELD_ID" -r '.data.node.fieldValues.nodes[] | select(.field.id==$FIELD_ID) | .date' project_item_data.json)"
# The value of the project item's 'Status' field (with ID `env.STATUS_FIELD_ID`)
echo "STATUS_FIELD_VALUE=$(jq --arg FIELD_ID "$STATUS_FIELD_ID" -r '.data.node.fieldValues.nodes[] | select(.field.id==$FIELD_ID) | .name' project_item_data.json)"
} >> "$GITHUB_ENV"
- name: Set status
# Only set the status if it's not already set,
# or if it's a reopened issue/PR (as they're marked as 'Done' when closed - see https://github.com/orgs/MAKENTNU/projects/1/workflows/3569450)
if: ${{ !env.STATUS_FIELD_VALUE || github.event.action == 'reopened' && env.STATUS_FIELD_VALUE == 'Done' }}
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
gh api graphql -f query='
mutation ($project: ID!, $item: ID!, $status_field: ID!, $status_value: String!) {
set_status: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $status_field
value: {
singleSelectOptionId: $status_value
}
}) {
projectV2Item {
id
}
}
}' -f project="$PROJECT_ID" -f item="$ITEM_ID" -f status_field="$STATUS_FIELD_ID" -f status_value="$STATUS_FIELD_VALUE_ID" --silent
- name: Get date
run: echo "DATE=$(TZ='Europe/Oslo' date --iso-8601)" >> "$GITHUB_ENV"

- name: Set date
# Only set the date if it's not already set
if: ${{ !env.DATE_FIELD_VALUE }}
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
gh api graphql -f query='
mutation ($project: ID!, $item: ID!, $date_field: ID!, $date_value: Date!) {
set_date_posted: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $date_field
value: {
date: $date_value
}
}) {
projectV2Item {
id
}
}
}' -f project="$PROJECT_ID" -f item="$ITEM_ID" -f date_field="$DATE_FIELD_ID" -f date_value="$DATE" --silent
13 changes: 13 additions & 0 deletions .github/workflows/project-add-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Add issues to project

on:
issues:
types: [ opened, reopened ]

jobs:
add_to_project:
uses: ./.github/workflows/_reusable_add-content-to-project.yml
with:
content_id: ${{ github.event.issue.node_id }}
status_field_value_name: "TODO"
secrets: inherit
15 changes: 15 additions & 0 deletions .github/workflows/project-add-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Add pull requests to project

on:
pull_request:
types: [ opened, reopened, ready_for_review ]

jobs:
add_to_project:
# Don't run the job if it's a draft PR
if: ${{ !github.event.pull_request.draft }}
uses: ./.github/workflows/_reusable_add-content-to-project.yml
with:
content_id: ${{ github.event.pull_request.node_id }}
status_field_value_name: "Ready for Review"
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4.1.0
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
Expand Down
Loading

0 comments on commit 6374f2f

Please sign in to comment.