Skip to content

Commit f0841e5

Browse files
chore: manage github repo and secrets with terraform
1 parent dcedda3 commit f0841e5

File tree

6 files changed

+156
-22
lines changed

6 files changed

+156
-22
lines changed

.github/workflows/publish.yml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
1-
name: Build and publish package
2-
31
on:
42
push:
53
branches:
64
- master
75

8-
env:
9-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
10+
name: Release and publish packages
1011

1112
jobs:
1213
release:
1314
runs-on: ubuntu-latest
14-
concurrency: release
15-
permissions:
16-
id-token: write
17-
contents: write
18-
1915
steps:
20-
# Checkout the repository
21-
- uses: actions/checkout@v3
16+
- uses: google-github-actions/release-please-action@v4
17+
id: release
2218
with:
23-
fetch-depth: 0
19+
token: ${{ secrets.GH_PAT }}
20+
config-file: release-please-config.json
21+
manifest-file: .release-please-manifest.json
2422

25-
# Set-up git user
26-
- name: Set-up git user
27-
run: |
28-
set -e
29-
git config user.name "github-actions[bot]"
30-
git config user.email "github-actions[bot]@users.noreply.github.com"
23+
# Check-out the repository
24+
- uses: actions/checkout@v4
25+
if: ${{ steps.release.outputs.release_created == 'true' }}
26+
with:
27+
ref: ${{ github.event.after }}
3128

3229
# Set up Python
3330
- uses: actions/setup-python@v1
31+
if: ${{ steps.release.outputs.release_created == 'true' }}
3432
with:
3533
python-version: 3.11
3634

3735
# Set up Poetry
3836
- uses: snok/install-poetry@v1
37+
if: ${{ steps.release.outputs.release_created == 'true' }}
3938
with:
4039
virtualenvs-create: true
4140
virtualenvs-in-project: true
@@ -44,20 +43,22 @@ jobs:
4443
- name: Load cached venv
4544
id: cache-dependencies
4645
uses: actions/cache@v3
46+
if: ${{ steps.release.outputs.release_created == 'true' }}
4747
with:
4848
path: .venv
4949
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
5050

5151
# Install dependencies
52-
- if: steps.cache-dependencies.outputs.cache-hit != 'true'
52+
- if: ${{ steps.release.outputs.release_created == 'true' && steps.cache-dependencies.outputs.cache-hit != 'true' }}
5353
run: poetry install --without test,dev
5454

55-
# Version package
56-
- run: poetry run semantic-release version
57-
5855
# Configure basic credentials for PyPI
5956
- run: poetry config pypi-token.pypi "${{ secrets.PYPI_PASSWORD }}"
57+
if: ${{ steps.release.outputs.release_created == 'true' }}
6058

6159
# Build and publish package
6260
- run: poetry build
61+
if: ${{ steps.release.outputs.release_created == 'true' }}
62+
6363
- run: poetry publish
64+
if: ${{ steps.release.outputs.release_created == 'true' }}

terraform/.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Sensitive values
2+
vars
3+
4+
# Local .terraform directories
5+
**/.terraform/*
6+
7+
# .tfstate files
8+
*.tfstate
9+
*.tfstate.*
10+
11+
# Crash log files
12+
crash.log
13+
crash.*.log
14+
15+
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
16+
# password, private keys, and other secrets. These should not be part of version
17+
# control as they are data points which are potentially sensitive and subject
18+
# to change depending on the environment.
19+
*.tfvars
20+
*.tfvars.json
21+
22+
# Ignore override files as they are usually used to override resources locally and so
23+
# are not checked in
24+
override.tf
25+
override.tf.json
26+
*_override.tf
27+
*_override.tf.json
28+
29+
# Include override files you do wish to add to version control using negated pattern
30+
# !example_override.tf
31+
32+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
33+
# example: *tfplan*
34+
35+
# Ignore CLI configuration files
36+
.terraformrc
37+
terraform.rc

terraform/.terraform.lock.hcl

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/main.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
resource "github_repository" "jtd_codebuild" {
2+
name = "jtd-codebuild"
3+
visibility = "public"
4+
homepage_url = "https://pypi.org/project/jtd-codebuild/"
5+
topics = [
6+
"code-generation",
7+
"json",
8+
"json-type-definition"
9+
]
10+
description = join(" ", [
11+
"Tool for generating language specific",
12+
"schemas and interfaces code from",
13+
"JSON Type Definition IDL files in yaml format.",
14+
"Powered by jtd-codegen.",
15+
])
16+
has_downloads = true
17+
has_issues = true
18+
has_projects = true
19+
has_wiki = true
20+
has_discussions = false
21+
}
22+
23+
resource "github_actions_secret" "pypi_username" {
24+
repository = github_repository.jtd_codebuild.name
25+
secret_name = "PYPI_USERNAME"
26+
plaintext_value = var.pypi_username
27+
}
28+
29+
resource "github_actions_secret" "pypi_password" {
30+
repository = github_repository.jtd_codebuild.name
31+
secret_name = "PYPI_PASSWORD"
32+
plaintext_value = var.pypi_password
33+
}
34+
35+
resource "github_actions_secret" "github_pat" {
36+
repository = github_repository.jtd_codebuild.name
37+
secret_name = "GH_PAT"
38+
plaintext_value = var.github_pat
39+
}

terraform/provider.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
terraform {
2+
required_providers {
3+
github = {
4+
source = "integrations/github"
5+
}
6+
}
7+
}
8+
9+
provider "github" {
10+
owner = var.github_owner
11+
}

terraform/variables.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
variable "github_owner" {
2+
type = string
3+
description = <<EOT
4+
Variable for GitHub owner.
5+
6+
This represents what account or organization the repository will be created under.
7+
EOT
8+
}
9+
10+
variable "github_pat" {
11+
type = string
12+
sensitive = true
13+
}
14+
15+
variable "pypi_username" {
16+
type = string
17+
sensitive = true
18+
}
19+
20+
variable "pypi_password" {
21+
type = string
22+
sensitive = true
23+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy