Skip to content

Commit 5ef4bf5

Browse files
authored
MRG: Merge pull request #1 from octue/testing/test-action
Finish GitHub action
2 parents cd44703 + e09ae29 commit 5ef4bf5

File tree

12 files changed

+1595
-53
lines changed

12 files changed

+1595
-53
lines changed

.github/workflows/release.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This workflow tests and releases a new version of the package.
2+
3+
name: Release
4+
5+
# Only trigger when a pull request into main branch is merged.
6+
on:
7+
pull_request:
8+
types: [closed]
9+
branches:
10+
- main
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Get package version
19+
id: get-package-version
20+
run: echo "PACKAGE_VERSION=$(poetry version -s)" >> $GITHUB_OUTPUT
21+
22+
- name: Create Release
23+
uses: actions/create-release@v1
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, no need to create your own.
26+
with:
27+
tag_name: ${{ steps.get-package-version.outputs.PACKAGE_VERSION }}
28+
release_name: ${{ github.event.pull_request.title }}
29+
body: ${{ github.event.pull_request.body }}
30+
draft: false
31+
prerelease: false
32+
33+
outputs:
34+
package_version: ${{ steps.get-package-version.outputs.PACKAGE_VERSION }}
35+
36+
docker:
37+
runs-on: ubuntu-latest
38+
needs: release
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v3
42+
43+
- name: Log in to DockerHub
44+
uses: docker/login-action@v2
45+
with:
46+
username: ${{ secrets.DOCKERHUB_USERNAME }}
47+
password: ${{ secrets.DOCKERHUB_TOKEN }}
48+
49+
- name: Build and push
50+
uses: docker/[email protected]
51+
with:
52+
context: .
53+
push: true
54+
tags: octue/get-deployment-info:${{ needs.release.outputs.package_version }},octue/get-deployment-info:latest

.github/workflows/semantic.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: semantic
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
check-semantic-version:
10+
if: "!contains(github.event.head_commit.message, 'skipci')"
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
# Set fetch-depth to 0 to fetch all tags (necessary for `git-mkver` to determine the correct semantic version).
16+
fetch-depth: 0
17+
- uses: octue/[email protected]
18+
with:
19+
path: pyproject.toml
20+
breaking_change_indicated_by: minor

.github/workflows/test.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: test-deployment-info
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
info:
8+
runs-on: ubuntu-latest
9+
10+
timeout-minutes: 5
11+
12+
permissions:
13+
contents: read
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Install poetry
20+
uses: snok/[email protected]
21+
22+
- name: Get deployment info
23+
id: get-deployment-info
24+
uses: ./
25+
with:
26+
gcp_project_name: test-project
27+
gcp_project_number: 1234
28+
gcp_region: europe-west1
29+
gcp_resource_affix: test
30+
gcp_service_name: my-test-service
31+
gcp_environment: main
32+
33+
- name: Print outputs
34+
run: |
35+
echo ${{ steps.get-deployment-info.outputs.branch_tag_kebab }}
36+
echo ${{ steps.get-deployment-info.outputs.branch_tag_screaming }}
37+
echo ${{ steps.get-deployment-info.outputs.image_latest_artefact }}
38+
echo ${{ steps.get-deployment-info.outputs.image_latest_tag }}
39+
echo ${{ steps.get-deployment-info.outputs.image_version_artefact }}
40+
echo ${{ steps.get-deployment-info.outputs.image_version_tag }}
41+
echo ${{ steps.get-deployment-info.outputs.short_sha }}
42+
echo ${{ steps.get-deployment-info.outputs.version_slug }}
43+
echo ${{ steps.get-deployment-info.outputs.gcp_environment }}
44+
echo ${{ steps.get-deployment-info.outputs.gcp_project_name }}
45+
echo ${{ steps.get-deployment-info.outputs.gcp_project_number }}
46+
echo ${{ steps.get-deployment-info.outputs.gcp_region }}
47+
echo ${{ steps.get-deployment-info.outputs.gcp_resource_affix }}
48+
echo ${{ steps.get-deployment-info.outputs.gcp_service_name }}
49+
echo ${{ steps.get-deployment-info.outputs.version }}

.github/workflows/update_pr.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This workflow updates the pull request description with an auto-generated section containing the categorised commit
2+
# message headers of the commits since the last pull request merged into main. The auto generated section is enveloped
3+
# between two comments: "<!--- START AUTOGENERATED NOTES --->" and "<!--- END AUTOGENERATED NOTES --->". Anything
4+
# outside these in the description is left untouched. Auto-generated updates are skipped if
5+
# "<!--- SKIP AUTOGENERATED NOTES --->" is added to the pull request description.
6+
7+
name: update-pr
8+
9+
on: [pull_request]
10+
11+
jobs:
12+
description:
13+
if: "!contains(github.event.pull_request.body, '<!--- SKIP AUTOGENERATED NOTES --->')"
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- uses: octue/[email protected]
19+
id: pr-description
20+
with:
21+
pull_request_url: ${{ github.event.pull_request.url }}
22+
api_token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Update pull request body
25+
uses: riskledger/update-pr-description@v2
26+
with:
27+
body: ${{ steps.pr-description.outputs.pull_request_description }}
28+
token: ${{ secrets.GITHUB_TOKEN }}

.pre-commit-config.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
exclude: "build|.git/|.tox|dist|.+.egg-info"
2+
default_stages: [commit]
3+
fail_fast: true
4+
default_language_version:
5+
python: python3 # force all unspecified python hooks to run python3
6+
repos:
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v4.3.0
9+
hooks:
10+
- id: trailing-whitespace
11+
- id: end-of-file-fixer
12+
- id: check-yaml
13+
- id: check-added-large-files
14+
15+
- repo: https://github.com/PyCQA/isort
16+
rev: 5.10.1
17+
hooks:
18+
- id: isort
19+
20+
- repo: https://github.com/psf/black
21+
rev: 22.6.0
22+
hooks:
23+
- id: black
24+
args: ["--line-length", "120"]
25+
26+
- repo: https://github.com/pycqa/flake8
27+
rev: 6.0.0
28+
hooks:
29+
- id: flake8
30+
language_version: python3
31+
additional_dependencies:
32+
- "pep8-naming"
33+
args:
34+
- --ignore-names=setUp,tearDown,setUpClass,tearDownClass,asyncSetUp,asyncTearDown,setUpTestData,failureException,longMessage,maxDiff,startTestRun,stopTestRun
35+
36+
- repo: https://github.com/pre-commit/mirrors-prettier
37+
rev: v2.7.1
38+
hooks:
39+
- id: prettier
40+
41+
- repo: https://github.com/windpioneers/pre-commit-hooks
42+
rev: 0.0.5
43+
hooks:
44+
- id: check-branch-name
45+
args:
46+
- "^main$"
47+
- "^development$"
48+
- "^devops/([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
49+
- "^doc/([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
50+
- "^feature/([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
51+
- "^enhancement/([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
52+
- "^fix/([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
53+
- "^hotfix/([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
54+
- "^review/([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
55+
- "^refactor/([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
56+
- "^test/([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
57+
- "^style/([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
58+
- "^deprecation/([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
59+
- "^dependencies/([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
60+
61+
- repo: https://github.com/octue/conventional-commits
62+
rev: 0.8.1
63+
hooks:
64+
- id: check-commit-message-is-conventional
65+
stages: [commit-msg]

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
FROM python:3.10.7-slim
22

3-
# Install poetry.
4-
ENV POETRY_HOME=/root/.poetry
5-
ENV PATH "$POETRY_HOME/bin:$PATH"
6-
RUN curl -sSL https://install.python-poetry.org | python3 - && poetry config virtualenvs.create false;
3+
RUN apt-get update -y && apt-get install -y --fix-missing curl git && rm -rf /var/lib/apt/lists/*
4+
5+
RUN pip3 install git+https://github.com/octue/[email protected]
76

87
COPY get_deployment_info/entrypoint.sh /entrypoint.sh
98

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[![Release](https://github.com/octue/get-deployment-info/actions/workflows/release.yml/badge.svg)](https://github.com/octue/get-deployment-info/actions/workflows/release.yml)
2+
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
3+
[![black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
4+
5+
# Get deployment info
6+
7+
A GitHub action that gets the information needed to build and deploy an Octue service to the cloud. This information is
8+
extracted and/or generated from:
9+
10+
- The action inputs
11+
- `git`
12+
- `pyproject.toml` or `setup.py`
13+
14+
## Usage
15+
16+
Add the action as a step in your workflow:
17+
18+
```yaml
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
23+
- name: Install poetry
24+
uses: snok/[email protected]
25+
26+
- name: Get deployment info
27+
id: get-deployment-info
28+
uses: octue/get-deployment-info
29+
with:
30+
gcp_project_name: test-project
31+
gcp_project_number: 1234
32+
gcp_region: europe-west1
33+
gcp_resource_affix: test
34+
gcp_service_name: my-test-service
35+
gcp_environment: main
36+
```
37+
38+
Outputs can be accessed in the usual way. For example, to print all the outputs:
39+
40+
```yaml
41+
- name: Print outputs
42+
run: |
43+
echo ${{ steps.get-deployment-info.outputs.branch_tag_kebab }}
44+
echo ${{ steps.get-deployment-info.outputs.branch_tag_screaming }}
45+
echo ${{ steps.get-deployment-info.outputs.image_latest_artefact }}
46+
echo ${{ steps.get-deployment-info.outputs.image_latest_tag }}
47+
echo ${{ steps.get-deployment-info.outputs.image_version_artefact }}
48+
echo ${{ steps.get-deployment-info.outputs.image_version_tag }}
49+
echo ${{ steps.get-deployment-info.outputs.short_sha }}
50+
echo ${{ steps.get-deployment-info.outputs.version_slug }}
51+
echo ${{ steps.get-deployment-info.outputs.gcp_environment }}
52+
echo ${{ steps.get-deployment-info.outputs.gcp_project_name }}
53+
echo ${{ steps.get-deployment-info.outputs.gcp_project_number }}
54+
echo ${{ steps.get-deployment-info.outputs.gcp_region }}
55+
echo ${{ steps.get-deployment-info.outputs.gcp_resource_affix }}
56+
echo ${{ steps.get-deployment-info.outputs.gcp_service_name }}
57+
echo ${{ steps.get-deployment-info.outputs.version }}
58+
```

action.yaml

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,69 @@
1-
name: 'Get deployment information'
1+
name: "Get deployment information"
22
description: "Get the information required to build and deploy an Octue service."
3-
author: 'cortadocodes'
3+
author: "cortadocodes"
44
#branding:
55
# icon: git-pull-request
66
# color: green
77
inputs:
88
gcp_project_name:
9-
description: ''
9+
description: "The name of the Google Cloud project being deployed to."
1010
required: true
1111
gcp_project_number:
12-
description: ''
12+
description: "The number of the Google Cloud project being deployed to."
1313
required: true
1414
gcp_region:
15-
description: ''
15+
description: "The Google Cloud region being deployed to."
1616
required: true
1717
gcp_resource_affix:
18-
description: ''
18+
description: ""
19+
required: true
20+
gcp_service_name:
21+
description: "The name of the service being deployed."
1922
required: true
2023
gcp_environment:
21-
description: ''
24+
description: ""
2225
required: false
2326
default: main
24-
gcp_service:
25-
description: ''
26-
required: true
2727

2828
outputs:
2929
branch_tag_kebab:
30-
description: ''
30+
description: "The tag or branch name in kebab case."
3131
branch_tag_screaming:
32-
description: ''
32+
description: "The tag or branch name in screaming snake case."
3333
image_latest_artefact:
34-
description: ''
34+
description: "The artefact URI for the latest docker image."
3535
image_latest_tag:
36-
description: ''
36+
description: "The tag of the latest docker image."
3737
image_version_artefact:
38-
description: ''
38+
description: "The artefact URI for the docker image for the version to deploy."
3939
image_version_tag:
40-
description: ''
40+
description: "The tag of the docker image for the version."
4141
short_sha:
42-
description: ''
42+
description: "The short SHA of the HEAD commit being deployed."
4343
version_slug:
44-
description: ''
44+
description: "The slugified version."
4545
gcp_environment:
46-
description: ''
46+
description: ""
4747
gcp_project_name:
48-
description: ''
48+
description: ""
4949
gcp_project_number:
50-
description: ''
50+
description: ""
5151
gcp_region:
52-
description: ''
52+
description: ""
5353
gcp_resource_affix:
54-
description: ''
54+
description: ""
5555
gcp_service:
56-
description: ''
56+
description: ""
5757
version:
58-
description: ''
58+
description: "The version being deployed."
5959

6060
runs:
61-
using: 'docker'
62-
# image: 'docker://octue/get-deployment-info:0.1.0'
63-
image: './Dockerfile'
64-
args:
65-
- ${{ inputs.gcp_project_name }}
66-
- ${{ inputs.gcp_project_number }}
67-
- ${{ inputs.gcp_region }}
68-
- ${{ inputs.gcp_resource_affix }}
69-
- ${{ inputs.gcp_environment }}
70-
- ${{ inputs.gcp_service }}
61+
using: "docker"
62+
image: "docker://octue/get-deployment-info:0.1.0"
63+
args:
64+
- ${{ inputs.gcp_project_name }}
65+
- ${{ inputs.gcp_project_number }}
66+
- ${{ inputs.gcp_region }}
67+
- ${{ inputs.gcp_resource_affix }}
68+
- ${{ inputs.gcp_service_name }}
69+
- ${{ inputs.gcp_environment }}

get_deployment_info/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)