-
Notifications
You must be signed in to change notification settings - Fork 9
138 lines (116 loc) · 4.25 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Release Packages
on:
push:
branches:
- main
paths:
- smithed_libraries/packs/**
- pyproject.toml
workflow_dispatch:
env:
MC_VERSION: '1.20'
COMMIT_MSG: ${{ github.event.head_commit.message }}
jobs:
build-linux:
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# Setup Build Environment
#----------------------------------------------
- name: Checkout 'main'
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Checkout 'releases'
uses: actions/checkout@v3
with:
path: 'releases'
ref: 'releases'
fetch-depth: 0
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Cache poetry
id: cache-poetry
uses: actions/cache@v3
with:
path: ~/.local
key: poetry-${{ runner.os }}
- name: Install Poetry
if: steps.cache-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
version: '1.2.2' # pinned to avoid CI bugs
virtualenvs-in-project: true
- name: Setup cache
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --with dev
#----------------------------------------------
# Build packs and copy to branch
#----------------------------------------------
- id: beet-build
name: Build via Beet
run: |
mkdir -p dist
cp releases/$MC_VERSION/manifest.json dist/manifest.json
poetry run python .github/workflows/build-changes.py
echo $(ls dist)
#----------------------------------------------
# Commit built packs to branch
#----------------------------------------------
# We use `&&` to ensure git steps are atomic
# TODO: Fix `git commit` message line
#----------------------------------------------
- id: push-to-branch
name: Copy and push release files to branch
if: steps.beet-build.outputs.build_changes == 'true'
run: |
set -e
mkdir -p releases/$MC_VERSION
cp -rf "dist/"* releases/$MC_VERSION
cd releases
SHORT_HASH=$(git rev-parse --short HEAD)
VERSION="${{ steps.pypi-release.outputs.version }}"
git add .
git config --global user.name "github-actions"
git config --global user.email "action@github.com"
git commit -m "🚀 $SHORT_HASH (v$VERSION): $COMMIT_MSG"
git push --force origin releases
echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
#----------------------------------------------
# Push to PYPI
#----------------------------------------------
- id: pypi-release
name: Release for PYPI
if: github.repository == 'Smithed-MC/Libraries'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
git config --global user.name "github-actions"
git config --global user.email "action@github.com"
poetry run semantic-release publish -v DEBUG -D commit_author="github-actions <action@github.com>"
echo "version=$(poetry run semantic-release print-version)" >> $GITHUB_OUTPUT
#----------------------------------------------
# Push packs to Smithed via API
#----------------------------------------------
# We load in a ton of data into env vars
#----------------------------------------------
- name: Push built packs to Smithed
if: steps.beet-build.outputs.build_changes == 'true'
run: poetry run python .github/workflows/push-to-smithed.py
env:
COMMIT_HASH: ${{ steps.push-to-branch.outputs.commit_hash}}
BUILT_PACKS: ${{ steps.beet-build.outputs.built_packs }}
SMITHED_UID: ${{ secrets.SMITHED_UID }}
SMITHED_TOKEN: ${{ secrets.SMITHED_TOKEN }}