-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adds explicit permissions - explicit ubuntu-24.04 runner - Don't persist git credentials if not needed - Avoid injection through metadata
- Loading branch information
Showing
7 changed files
with
76 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,23 @@ on: | |
description: "Tag to release" | ||
required: true | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
image: | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-24.04 | ||
name: Release Actions | ||
permissions: | ||
contents: read | ||
packages: write | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: true | ||
|
||
- name: Check tofu actions are up to date | ||
run: | | ||
|
@@ -38,14 +46,14 @@ jobs: | |
|
||
- name: Build action image | ||
id: image_build | ||
env: | ||
RELEASE_TAG: "${{ github.event.release.tag_name }}${{ github.event.inputs.tag_name }}" | ||
run: | | ||
RELEASE_TAG="${{ github.event.release.tag_name }}${{ github.event.inputs.tag_name }}" | ||
docker buildx build \ | ||
--build-arg FETCH_CHECKSUMS=yes \ | ||
--build-arg VERSION="${RELEASE_TAG:1}" \ | ||
--tag danielflook/terraform-github-actions:$RELEASE_TAG \ | ||
--tag ghcr.io/dflook/terraform-github-actions:$RELEASE_TAG \ | ||
--tag "danielflook/terraform-github-actions:$RELEASE_TAG" \ | ||
--tag "ghcr.io/dflook/terraform-github-actions:$RELEASE_TAG" \ | ||
--platform linux/amd64,linux/arm64 \ | ||
--attest type=provenance,mode=max,builder-id=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID \ | ||
--push \ | ||
|
@@ -55,29 +63,31 @@ jobs: | |
echo "digest=$(<manifest-list-digest.txt)" >> "$GITHUB_OUTPUT" | ||
- name: Release actions | ||
env: | ||
RELEASE_TAG: "${{ github.event.release.tag_name }}${{ github.event.inputs.tag_name }}" | ||
IMAGE_DIGEST: ${{ steps.image_build.outputs.digest }} | ||
run: | | ||
export RELEASE_TAG="${{ github.event.release.tag_name }}${{ github.event.inputs.tag_name }}" | ||
export major=$(echo $RELEASE_TAG | cut -d. -f1) | ||
export minor=$(echo $RELEASE_TAG | cut -d. -f2) | ||
export major=$(echo "$RELEASE_TAG" | cut -d. -f1) | ||
export minor=$(echo "$RELEASE_TAG" | cut -d. -f2) | ||
git config --global user.name "Daniel Flook" | ||
git config --global user.email "[email protected]" | ||
function prepare_release() { | ||
rsync -r $GITHUB_WORKSPACE/$action/ $HOME/$action | ||
rm -rf $HOME/$action/.github | ||
mkdir $HOME/$action/.github | ||
cp $GITHUB_WORKSPACE/.github/FUNDING.yml $HOME/$action/.github/FUNDING.yml | ||
rsync -r "$GITHUB_WORKSPACE/$action/" "$HOME/$action" | ||
rm -rf "$HOME/$action/.github" | ||
mkdir "$HOME/$action/.github" | ||
cp "$GITHUB_WORKSPACE/.github/FUNDING.yml" "$HOME/$action/.github/FUNDING.yml" | ||
} | ||
for action in $(cd $GITHUB_WORKSPACE && find . -name action.yaml -printf "%h\n" | sed 's/^.\///'); do | ||
for action in $(cd "$GITHUB_WORKSPACE" && find . -name action.yaml -printf "%h\n" | sed 's/^.\///'); do | ||
if git clone https://dflook:[email protected]/dflook/$action.git "$HOME/$action"; then | ||
if git clone "https://dflook:[email protected]/dflook/$action.git" "$HOME/$action"; then | ||
echo "Releasing dflook/$action@$RELEASE_TAG" | ||
# git tags that use DockerHub for the image | ||
prepare_release | ||
sed -i 's| image:.*| image: docker://danielflook/terraform-github-actions@${{ steps.image_build.outputs.digest }}|' $HOME/$action/action.yaml | ||
sed -i "s| image:.*| image: docker://danielflook/terraform-github-actions@$IMAGE_DIGEST|" "$HOME/$action/action.yaml" | ||
git -C "$HOME/$action" add -A | ||
git -C "$HOME/$action" commit -m "$RELEASE_TAG" | ||
|
@@ -90,7 +100,7 @@ jobs: | |
# git tags that use GitHub Container Registry for the image | ||
git -C "$HOME/$action" checkout ghcr || git -C "$HOME/$action" checkout -b ghcr | ||
prepare_release | ||
sed -i 's| image:.*| image: docker://ghcr.io/dflook/terraform-github-actions@${{ steps.image_build.outputs.digest }}|' $HOME/$action/action.yaml | ||
sed -i "s| image:.*| image: docker://ghcr.io/dflook/terraform-github-actions@$IMAGE_DIGEST|" "$HOME/$action/action.yaml" | ||
git -C "$HOME/$action" add -A | ||
git -C "$HOME/$action" commit -m "$RELEASE_TAG-ghcr" | ||
|
@@ -101,11 +111,11 @@ jobs: | |
git -C "$HOME/$action" push --force --tags | ||
# Create the github release | ||
cat $GITHUB_WORKSPACE/.github/release_template.md \ | ||
cat "$GITHUB_WORKSPACE/.github/release_template.md" \ | ||
| envsubst \ | ||
| jq --slurp --raw-input --arg RELEASE_TAG "$RELEASE_TAG" '{"tag_name": $RELEASE_TAG, "name": $RELEASE_TAG, "body": . }' \ | ||
| curl -X POST \ | ||
--user dflook:$GITHUB_TOKEN \ | ||
--user "dflook:$GITHUB_TOKEN" \ | ||
--header "Content-Type: application/json" \ | ||
--data-binary @- \ | ||
"https://api.github.com/repos/dflook/$action/releases" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters