Skip to content

Commit

Permalink
chore: update workflows and clean task (#1672)
Browse files Browse the repository at this point in the history
  • Loading branch information
onedr0p authored Jan 3, 2025
1 parent 089123b commit 70fbd00
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 52 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ on:
workflow_dispatch:
pull_request:
branches: ["main"]
paths-ignore:
- kubernetes/**

concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true

jobs:

configure:
if: ${{ github.repository == 'onedr0p/cluster-template' }}
name: configure
Expand All @@ -29,28 +30,23 @@ jobs:
- name: Setup mise
uses: jdx/mise-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

- name: Install Python dependencies
shell: bash
run: mise run pip

- name: Run Sops Age key task
shell: bash
- name: Run age task
run: task bootstrap:age-keygen

- name: Run init tasks
shell: bash
- name: Run init task
run: |
task init
cp ./.github/tests/config-${{ matrix.config-files }}.yaml ./config.yaml
export BOOTSTRAP_AGE_PUBLIC_KEY=$(sed -n 's/# public key: //gp' age.key)
envsubst < ./config.yaml > ./config.yaml.tmp && mv ./config.yaml.tmp ./config.yaml
- name: Run configure task
shell: bash
run: task configure --yes

- name: Run clean
shell: bash
- name: Run clean task
run: task bootstrap:clean
1 change: 0 additions & 1 deletion .github/workflows/kubeconform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ jobs:
run: brew install fluxcd/tap/flux kubeconform kustomize

- name: Run kubeconform
shell: bash
run: bash ./scripts/kubeconform.sh ${{ env.KUBERNETES_DIR }}
69 changes: 40 additions & 29 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,51 @@ name: "Release"
on:
workflow_dispatch:
schedule:
- cron: "0 0 1 * *"
- cron: "0 0 1 * *" # 1st of every month at midnight

jobs:
release:
if: ${{ github.repository == 'onedr0p/cluster-template' }}
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get Previous Release Tag and Determine Next Tag
id: determine-next-tag
uses: actions/github-script@v7
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
result-encoding: string
script: |
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 1,
});
let previousTag = "0.0.0"; // Default if no previous release exists
if (releases.length > 0) {
previousTag = releases[0].tag_name;
}
const [previousMajor, previousMinor, previousPatch] = previousTag.split('.').map(Number);
const currentYear = new Date().getFullYear();
const currentMonth = new Date().getMonth() + 1; // Months are 0-indexed in JavaScript
const nextMajorMinor = `${currentYear}.${currentMonth}`;
let nextPatch;
if (`${previousMajor}.${previousMinor}` === nextMajorMinor) {
console.log("Month release already exists for the year. Incrementing patch number by 1.");
nextPatch = previousPatch + 1;
} else {
console.log("Month release does not exist for the year. Starting with patch number 0.");
nextPatch = 0;
}
return `${nextMajorMinor}.${nextPatch}`;
- name: Create Release
shell: bash
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
run: |
# Retrieve previous release tag
previous_tag="$(gh release list --limit 1 | awk '{ print $1 }')"
previous_major="${previous_tag%%\.*}"
previous_minor="${previous_tag#*.}"
previous_minor="${previous_minor%.*}"
previous_patch="${previous_tag##*.}"
# Determine next release tag
next_major_minor="$(date +'%Y').$(date +'%-m')"
if [[ "${previous_major}.${previous_minor}" == "${next_major_minor}" ]]; then
echo "Month release already exists for year, incrementing patch number by 1"
next_patch="$((previous_patch + 1))"
else
echo "Month release does not exist for year, setting patch number to 0"
next_patch="0"
fi
# Create release
release_tag="${next_major_minor}.${next_patch}"
gh release create "${release_tag}" \
--repo="${GITHUB_REPOSITORY}" \
--title="${release_tag}" \
--generate-notes
uses: ncipollo/release-action@v1
with:
generateReleaseNotes: true
tag: "${{ steps.determine-next-tag.outputs.result }}"
token: "${{ secrets.GITHUB_TOKEN }}"
15 changes: 7 additions & 8 deletions .taskfiles/bootstrap/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,18 @@ tasks:
clean:
desc: Clean files and directories no longer needed after cluster bootstrap
cmds:
# Create backup directory
- mkdir -p {{.ROOT_DIR}}/.private
# Clean up CI
- mkdir -p {{.ROOT_DIR}}/.private/{{.TS}}
- mv {{.BOOTSTRAP_DIR}} {{.ROOT_DIR}}/.private/{{.TS}}/bootstrap
- mv {{.MAKEJINJA_CONFIG_FILE}} {{.ROOT_DIR}}/.private/{{.TS}}/makejinja.toml
- mv {{.ROOT_DIR}}/requirements.txt {{.ROOT_DIR}}/.private/{{.TS}}/requirements.txt
- rm -rf {{.ROOT_DIR}}/.github/tests
- rm -rf {{.ROOT_DIR}}/.github/workflows/e2e.yaml
# Move bootstrap directory to gitignored directory
- mv {{.BOOTSTRAP_DIR}} {{.ROOT_DIR}}/.private/bootstrap-{{.TS}}
- mv {{.MAKEJINJA_CONFIG_FILE}} {{.ROOT_DIR}}/.private/makejinja-{{.TS}}.toml
- mv {{.ROOT_DIR}}/requirements.txt {{.ROOT_DIR}}/.private/requirements.txt
# Update renovate.json5
- sed -i {{if eq OS "darwin"}}''{{end}} 's/(..\.j2)\?//g' {{.ROOT_DIR}}/.github/renovate.json5
vars:
TS: '{{now | unixEpoch}}'
preconditions:
- test -d {{.BOOTSTRAP_DIR}}
- test -d {{.ROOT_DIR}}/.github/tests
- test -f {{.MAKEJINJA_CONFIG_FILE}}
- test -f {{.ROOT_DIR}}/.github/renovate.json5
- test -f {{.ROOT_DIR}}/requirements.txt
5 changes: 1 addition & 4 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ tasks:
- task: bootstrap:template
- task: bootstrap:secrets
- task: kubernetes:kubeconform
- >
{{if eq .HOME_SOPS_AGE_KEY_FILE_EXISTS "true"}}
echo "WARNING: SOPS Age key found in home directory, this may cause conflicts."
{{end}}
- '{{if eq .HOME_SOPS_AGE_KEY_FILE_EXISTS "true"}}echo "WARNING: SOPS Age key found in home directory, this may cause conflicts."{{end}}'
vars:
HOME_SOPS_AGE_KEY_FILE_EXISTS:
sh: test -f ~/.config/sops/age/keys.txt && echo true || echo false

0 comments on commit 70fbd00

Please sign in to comment.