Skip to content

Commit 0f71c7d

Browse files
committed
Reset the local workspace to the versioned commit
Signed-off-by: Kyle Harding <[email protected]>
1 parent 67c2f9b commit 0f71c7d

File tree

2 files changed

+71
-54
lines changed

2 files changed

+71
-54
lines changed

.github/workflows/flowzone.yml

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

flowzone.yml

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,53 +1333,71 @@ jobs:
13331333
REF: "refs/tags/${{ steps.versionist.outputs.tag }}"
13341334
SHA: ${{ steps.create_tag.outputs.sha }}
13351335

1336-
# Checkout the versioned commit we created in the previous steps.
1337-
# This may seem wasteful, to clone the sources again, but we plan to move
1338-
# the versioning steps above out of Flowzone entirely and clone from a
1339-
# branch created by a dedicated GitHub App.
1340-
- name: Checkout versioned commit
1341-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1336+
# # Checkout the versioned commit we created in the previous steps.
1337+
# # This may seem wasteful, to clone the sources again, but we plan to move
1338+
# # the versioning steps above out of Flowzone entirely and clone from a
1339+
# # branch created by a dedicated GitHub App.
1340+
# - name: Checkout versioned commit
1341+
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1342+
# with:
1343+
# # Should be 0 (full depth) if submodules are present, otherwise 1
1344+
# fetch-depth: ${{ steps.git_describe.outputs.depth || 0 }}
1345+
# # Note that fetch-tags is not currently working as described:
1346+
# # https://github.com/actions/checkout/issues/1781
1347+
# fetch-tags: false
1348+
# submodules: "recursive"
1349+
# # fallback to an invalid ref if the checkout ref is undefined
1350+
# ref: "${{ steps.create_commit.outputs.sha || '¯\_(ツ)_/¯' }}"
1351+
# path: versioned-source
1352+
# <<: *checkoutAuth
1353+
1354+
# Create base64 encoded auth header
1355+
- name: Create base64 encoded auth header
1356+
id: auth_header
1357+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
1358+
env:
1359+
GIT_AUTH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
13421360
with:
1343-
# Should be 0 (full depth) if submodules are present, otherwise 1
1344-
fetch-depth: ${{ steps.git_describe.outputs.depth || 0 }}
1345-
# Note that fetch-tags is not currently working as described:
1346-
# https://github.com/actions/checkout/issues/1781
1347-
fetch-tags: false
1348-
submodules: "recursive"
1349-
# fallback to an invalid ref if the checkout ref is undefined
1350-
ref: "${{ steps.create_commit.outputs.sha || '¯\_(ツ)_/¯' }}"
1351-
path: versioned-source
1352-
<<: *checkoutAuth
1353-
1354-
# Create a local reference for the versioned tag.
1355-
# On open PRs, the tag doesn't exist yet, we couldn't fetch it anyway.
1356-
# On merged PRs, the tag fetch doesn't work correctly with fetch-depth > 0
1361+
result-encoding: string
1362+
script: |
1363+
const token = process.env.GIT_AUTH_TOKEN;
1364+
const authHeader = Buffer.from(`x-access-token:${token}`).toString('base64');
1365+
core.setSecret(authHeader);
1366+
core.setOutput('config', `http.https://github.com/.extraheader=Authorization: basic ${authHeader}`);
1367+
return authHeader;
1368+
1369+
# Reset the local workspace to the versioned commit we just created
1370+
# and add a local annotated tag.
13571371
# https://github.com/actions/checkout/issues/1781
1358-
- name: Create local tag for draft versions
1359-
if: inputs.disable_versioning != true
1360-
working-directory: versioned-source
1372+
- name: Create a local versioned commit + tag
1373+
if: steps.versionist.outputs.tag && steps.create_commit.outputs.sha
13611374
env:
1375+
AUTH_CONFIG: ${{ steps.auth_header.outputs.config }}
13621376
GIT_AUTHOR_NAME: "${{ steps.create_commit.outputs.author }}"
13631377
GIT_AUTHOR_EMAIL: "${{ steps.create_commit.outputs.author_email }}"
13641378
GIT_COMMITTER_NAME: "${{ steps.create_commit.outputs.author }}"
13651379
GIT_COMMITTER_EMAIL: "${{ steps.create_commit.outputs.author_email }}"
1366-
REF: refs/tags/${{ steps.versionist.outputs.tag }}
1380+
TAG: ${{ steps.versionist.outputs.tag }}
13671381
SHA: ${{ steps.create_commit.outputs.sha }}
1382+
# Use git-c for non-persistent credential configuration
1383+
#
1384+
# The git -c option sets a configuration value for a single Git command invocation.
1385+
# It does not modify any configuration files or persist the setting beyond this specific command.
1386+
#
1387+
# This approach ensures that the authentication credentials are used securely for this
1388+
# specific operation without risk of unintended persistence or exposure in configuration files.
13681389
run: |
1369-
git update-ref "${REF}" "${SHA}"
1390+
git -c "${AUTH_CONFIG}" fetch origin "${SHA}"
1391+
git reset --hard "${SHA}"
1392+
git tag --annotate "${TAG}" --message "${TAG}" --force
13701393
13711394
# Reset the .github directory to the GitHub ref
13721395
# For security, this is the tip of BASE if the event is pull_request_target
13731396
# or the merge commit if the PR is internal
13741397
- name: Reset .github directory to ${{ github.ref }}
1375-
working-directory: versioned-source
13761398
env:
1377-
GIT_AUTH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
1399+
AUTH_CONFIG: ${{ steps.auth_header.outputs.config }}
13781400
REF: ${{ github.ref }}
1379-
# Use bash without tracing to avoid leaking secrets
1380-
shell: bash
1381-
# Create base64 encoded auth header
1382-
#
13831401
# Use git-c for non-persistent credential configuration
13841402
#
13851403
# The git -c option sets a configuration value for a single Git command invocation.
@@ -1388,14 +1406,12 @@ jobs:
13881406
# This approach ensures that the authentication credentials are used securely for this
13891407
# specific operation without risk of unintended persistence or exposure in configuration files.
13901408
run: |
1391-
auth_header=$(printf "x-access-token:${GIT_AUTH_TOKEN}" | base64 | tr -d '\n')
1392-
git -c "http.https://github.com/.extraheader=Authorization: basic ${auth_header}" fetch origin "${REF}"
1409+
git -c "${AUTH_CONFIG}" fetch origin "${REF}"
13931410
git checkout FETCH_HEAD -- .github
13941411
13951412
# Compress versioned source to maintain file permissions and case-sensitivity
13961413
# https://github.com/actions/upload-artifact#maintaining-file-permissions-and-case-sensitive-files
13971414
- name: Compress versioned source
1398-
working-directory: versioned-source
13991415
run: tar --auto-compress --create --file ${{ runner.temp }}/versioned_source.tar.zst .
14001416

14011417
# This artifact is consumed by all other jobs instead of re-cloning the sources.

0 commit comments

Comments
 (0)