Skip to content

Commit c428d97

Browse files
authored
Merge pull request #5 from rivian/ci/no-third-party-actions
Replace third-party actions with shell steps in workflows
2 parents c945d16 + a154b9f commit c428d97

2 files changed

Lines changed: 51 additions & 35 deletions

File tree

‎.github/workflows/documentation.yaml‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,35 @@ name: Docs
22
on: [push, pull_request, workflow_dispatch]
33
permissions:
44
contents: write
5+
# Org policy only allows actions from rivian-owned repos, so every step here is
6+
# a plain shell command instead of a `uses:` action.
57
jobs:
68
docs:
79
runs-on: ubuntu-latest
810
steps:
9-
- uses: actions/checkout@v3
10-
- uses: actions/setup-python@v3
11+
- name: Checkout
12+
run: |
13+
git init .
14+
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
15+
git fetch --depth 1 origin "$GITHUB_SHA"
16+
git checkout FETCH_HEAD
1117
- name: Install dependencies
1218
run: |
13-
pip install sphinx sphinx_rtd_theme myst-parser
19+
python3 -m venv .venv
20+
.venv/bin/pip install sphinx sphinx_rtd_theme myst-parser
1421
- name: Sphinx build
1522
run: |
16-
sphinx-build docs/source build
23+
.venv/bin/sphinx-build docs/source build
1724
- name: Deploy
18-
uses: peaceiris/actions-gh-pages@v3
1925
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
20-
with:
21-
publish_branch: gh-pages
22-
github_token: ${{ secrets.GITHUB_TOKEN }}
23-
publish_dir: build/
24-
force_orphan: true
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
run: |
29+
cd build
30+
touch .nojekyll
31+
git init -b gh-pages .
32+
git config user.name "github-actions[bot]"
33+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
34+
git add -A
35+
git commit -m "Deploy docs from $GITHUB_SHA"
36+
git push --force "https://x-access-token:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY" gh-pages

‎.github/workflows/publish.yaml‎

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,43 @@ name: Publish
22
on:
33
push:
44
tags: ['*']
5+
# Org policy only allows actions from rivian-owned repos, so every step here is
6+
# a plain shell command instead of a `uses:` action.
57
jobs:
6-
build:
8+
publish:
79
runs-on: ubuntu-latest
10+
environment: pypi
11+
permissions:
12+
contents: read
13+
id-token: write
814
steps:
9-
- uses: actions/checkout@v4
10-
- uses: actions/setup-python@v5
11-
with:
12-
python-version: '3.x'
15+
- name: Checkout
16+
run: |
17+
git init .
18+
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
19+
git fetch --depth 1 origin "$GITHUB_SHA"
20+
git checkout FETCH_HEAD
1321
- name: Check tag matches package version
1422
run: |
15-
version=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
23+
version=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
1624
if [ "$version" != "$GITHUB_REF_NAME" ]; then
1725
echo "Tag $GITHUB_REF_NAME does not match pyproject.toml version $version"
1826
exit 1
1927
fi
2028
- name: Build
2129
run: |
22-
pip install build twine
23-
python -m build
24-
twine check dist/*
25-
- uses: actions/upload-artifact@v4
26-
with:
27-
name: dist
28-
path: dist/
29-
publish:
30-
needs: build
31-
runs-on: ubuntu-latest
32-
environment: pypi
33-
permissions:
34-
id-token: write
35-
steps:
36-
- uses: actions/download-artifact@v4
37-
with:
38-
name: dist
39-
path: dist/
40-
- uses: pypa/gh-action-pypi-publish@release/v1
30+
python3 -m venv .venv
31+
.venv/bin/pip install build twine
32+
.venv/bin/python -m build
33+
.venv/bin/twine check dist/*
34+
- name: Publish to PyPI
35+
# Trusted publishing: exchange the GitHub OIDC token for a short-lived
36+
# PyPI upload token (what pypa/gh-action-pypi-publish does internally).
37+
run: |
38+
set -euo pipefail
39+
oidc=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
40+
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi" | jq -r .value)
41+
token=$(curl -sSf -X POST https://pypi.org/_/oidc/mint-token \
42+
-d "{\"token\": \"$oidc\"}" | jq -r .token)
43+
echo "::add-mask::$token"
44+
TWINE_USERNAME=__token__ TWINE_PASSWORD="$token" .venv/bin/twine upload dist/*

0 commit comments

Comments
 (0)