Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix versioning logic #4

Merged
merged 35 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
aa09131
Test without split
audunsolemdal Nov 29, 2023
44a78c3
tweak
audunsolemdal Nov 29, 2023
5660b00
Tweak
audunsolemdal Nov 29, 2023
2ae932f
Tweak
audunsolemdal Nov 29, 2023
4e0279d
Tweak
audunsolemdal Nov 29, 2023
d6734c4
test
audunsolemdal Nov 29, 2023
c7f0f19
test
audunsolemdal Nov 29, 2023
ee3936f
Tweak
audunsolemdal Nov 29, 2023
b1f6d0c
Tweak
audunsolemdal Nov 29, 2023
dc6ca0f
Tweak
audunsolemdal Nov 29, 2023
1b7e219
Tweak
audunsolemdal Nov 29, 2023
d275ffc
Tweak
audunsolemdal Nov 29, 2023
14cebaf
Tweak
audunsolemdal Nov 29, 2023
11b5df3
Tweak
audunsolemdal Nov 29, 2023
64856bc
Update wf
audunsolemdal Nov 29, 2023
6b9183f
Fixes
audunsolemdal Nov 29, 2023
544b399
Tweak
audunsolemdal Nov 29, 2023
cadfdad
Trigger
audunsolemdal Nov 29, 2023
31e7595
Try nul
audunsolemdal Nov 29, 2023
944afe7
Debug
audunsolemdal Nov 29, 2023
cd63b05
Debug
audunsolemdal Nov 29, 2023
4b41532
Debug
audunsolemdal Nov 29, 2023
02fd4bc
Debug
audunsolemdal Nov 29, 2023
5070d40
empty commit to trigger wf
audunsolemdal Nov 29, 2023
0d0b98f
empty commit to trigger wf
audunsolemdal Nov 29, 2023
b1dfefa
Debug
audunsolemdal Nov 29, 2023
80c9a38
empty commit to trigger wf
audunsolemdal Nov 29, 2023
0a4683e
Add default package name
audunsolemdal Nov 29, 2023
d0ae297
Spacing
audunsolemdal Nov 29, 2023
9b9a02c
String
audunsolemdal Nov 29, 2023
4e9b981
String
audunsolemdal Nov 29, 2023
04d001d
Tweak
audunsolemdal Nov 29, 2023
17abe90
Tweak
audunsolemdal Nov 29, 2023
e3c7445
Tweak
audunsolemdal Nov 29, 2023
3cc1637
Remove comment
audunsolemdal Nov 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,31 @@ jobs:
const { sha, releases } = JSON.parse(process.env.CLIENT_PAYLOAD);

for (const release of releases) {
const tagName = `${release.module}/${release.newVersion}`;
let tagName = `${release.module}/${release.newVersion}`;

if (release.module == "main")
{
tagName = `${release.newVersion}`;
}

let ref = `refs/tags/${tagName}`;
console.log('Tagging', tagName, 'as', sha);
await github.rest.git.createRef({ owner, repo, ref, sha });

const releaseVersion = `${release.newVersion}`;
const module = `${release.module}`;
let module = `${release.module}` + "/v";
if (module == "main/v")
{
module = "v";
}

try {
ref = "tags/" + module + "/v" + releaseVersion.split(".")[0]
ref = "tags/" + module + releaseVersion.split(".")[0]
console.log('Updating existing tag', ref, 'as', sha);
await github.rest.git.updateRef({ owner, repo, ref, sha });
}
catch {
ref = "refs/tags/" + module + "/v" + releaseVersion.split(".")[0]
ref = "refs/tags/" + module + releaseVersion.split(".")[0]
console.log('Creating new tag', ref, 'as', sha);
await github.rest.git.createRef({ owner, repo, ref, sha });
}
Expand Down
34 changes: 26 additions & 8 deletions .github/workflows/generate-release-metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ on:
description: "Write Terraform docs to wiki or not"
required: false
default: "false"

jobs:
detect:
runs-on: ubuntu-latest
Expand All @@ -40,8 +41,6 @@ jobs:
&& github.event.action == 'closed'
&& github.event.pull_request.merged == true }}
steps:
# I'm getting the labels from the API and not the context("contains(github.event.pull_request.labels.*.name, 'Env Promote')") as the labels
# are added in 2nd API call so they aren't included in the PR context
- name: Check PR labels
id: check_pr_label
env:
Expand Down Expand Up @@ -73,12 +72,22 @@ jobs:
with:
script: |
const raw = JSON.parse(process.env.RAW_FILES);
const directories = Array.from(new Set(raw
let directories = Array.from(new Set(raw
.filter(x => x.startsWith('${{ inputs.rootFolder }}'))
.filter(x => x.includes('/'))
.map(x => x.split('/')[${{ inputs.index-split }}])
.map(x => x.split('.')[0])
));
if (directories.length < 1 && ${{ inputs.rootFolder == '/' }})
{
directories = Array.from(new Set(raw
.filter(x => x.includes('.tf'))
.filter(x => !x.startsWith('.'))
.filter(x => !x.includes('modules'))
.filter(x => !x.includes('examples'))
.map(x => x.substr(0, x.lastIndexOf('/')))
));
}
if (directories.length < 1) return {};
return {
include: directories.map(directory => ({ directory })),
Expand All @@ -92,15 +101,15 @@ jobs:
pull-requests: read
runs-on: ubuntu-latest
strategy:
matrix: "${{ fromJson(needs.detect.outputs.directories) }}"
matrix: ${{ fromJson(needs.detect.outputs.directories) }}
fail-fast: false
name: "Module: ${{ matrix.directory }}"
steps:
- name: Detect previous version number
uses: actions/github-script@v7
id: prev-version
env:
PACKAGE_NAME: "${{ matrix.directory }}"
PACKAGE_NAME: "${{ matrix.directory || 'main' }}"
with:
script: |
const { owner, repo } = context.repo;
Expand All @@ -111,10 +120,19 @@ jobs:
}
}
}`;

let refPrefix = `refs/tags/${process.env.PACKAGE_NAME}/`;
if (process.env.PACKAGE_NAME == 'main')
{
refPrefix = 'refs/tags/';
}
console.log('Querying for previous version', refPrefix);

const result = await github.graphql(query, { owner, repo,
refPrefix: `refs/tags/${process.env.PACKAGE_NAME}/`,
refPrefix: refPrefix,
first: 1,
});

const prevNode = result.repository.refs.edges[0];
let prevVer = prevNode ? prevNode.node.name : '0.0.0';
console.log('Found previous version', prevVer);
Expand All @@ -123,7 +141,7 @@ jobs:
{
console.log("Newest tag starts with 'v', attempting to fetch second newest tag...")
const result = await github.graphql(query, { owner, repo,
refPrefix: `refs/tags/${process.env.PACKAGE_NAME}/`,
refPrefix: refPrefix,
first: 2,
});
const prevNode = result.repository.refs.edges[1];
Expand Down Expand Up @@ -267,7 +285,7 @@ jobs:
- name: Upload result artifacts
uses: actions/upload-artifact@v3
with:
name: "${{ matrix.directory }}"
name: "${{ matrix.directory || 'main' }}"
path: output
retention-days: 5

Expand Down