Skip to content

Commit

Permalink
RELENG-5805 fix artifacts match on promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet committed Apr 14, 2022
1 parent 40ba53f commit 0233a68
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test-prolong.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ jobs:
run: |
echo ${{ steps.artifacts-prolong.outputs.name }}
echo ${{ steps.artifacts-prolong.outputs.link }}
- name: Get prolonged artifacts
run: |
curl -u ${{ secrets.ARTIFACTS_USER }}:${{ secrets.ARTIFACTS_PASSWORD }} ${{ steps.artifacts-prolong.outputs.link }}/.final_status
4 changes: 4 additions & 0 deletions .github/workflows/test-promote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ jobs:
run: |
echo ${{ steps.artifacts-promote.outputs.name }}
echo ${{ steps.artifacts-promote.outputs.link }}
- name: Get promoted artifacts
run: |
curl -u ${{ secrets.ARTIFACTS_USER }}:${{ secrets.ARTIFACTS_PASSWORD }} ${{ steps.artifacts-promote.outputs.link }}/.final_status
- name: Tag the repo
run: git tag 1.0.1
- name: Artifacts Promote
Expand Down
33 changes: 20 additions & 13 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export enum Inputs {
Password = 'password',
Url = 'url',
Method = 'method',
Name = 'name',
Tag = 'tag',
Source = 'source',
Workflow_name = 'workflow-name'
Expand Down
8 changes: 5 additions & 3 deletions src/inputs-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function getInputs(): InputsArtifacts {
let source = ''
let tag = ''
let workflow_name = ''
let name = ''

const url = core.getInput(Inputs.Url, {required: true})

Expand All @@ -35,10 +36,10 @@ export function getInputs(): InputsArtifacts {
}
method = upload
} else if (method_type === Methods.Prolong) {
workflow_name = core.getInput(Inputs.Workflow_name, {required: true})
name = core.getInput(Inputs.Name, {required: true})
method = prolong
} else if (method_type === Methods.Promote) {
workflow_name = core.getInput(Inputs.Workflow_name, {required: true})
name = core.getInput(Inputs.Name, {required: true})
tag = core.getInput(Inputs.Tag, {required: true})
method = promote
} else if (method_type === Methods.Get) {
Expand All @@ -58,6 +59,7 @@ export function getInputs(): InputsArtifacts {
tag,
method,
method_type,
workflow_name
workflow_name,
name
} as InputsArtifacts
}
1 change: 1 addition & 0 deletions src/inputs-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface InputsArtifacts {
url: string
method: (x: InputsArtifacts) => Promise<void>
method_type: string
name: string
tag: string
source: string
workflow_name: string
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function run(): Promise<void> {
const inputs = getInputs()

core.info(`Method ${inputs.method_type} has been selected`)
inputs.method(inputs)
await inputs.method(inputs)
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}
Expand Down
24 changes: 15 additions & 9 deletions src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ export async function promote(inputs: InputsArtifacts): Promise<void> {
)
const promoted_regex = new RegExp('(^[^/]+:)promoted-([^/]+)$')

const staging_match = inputs.workflow_name.match(staging_regex)
const promoted_match = inputs.workflow_name.match(promoted_regex)
const staging_match = inputs.name.match(staging_regex)
const promoted_match = inputs.name.match(promoted_regex)

let artifacts_commit = ''
let artifacts_prefix = ''
if (staging_match !== null) {
core.info('Staging artifacts has been selected')
artifacts_commit = staging_match[3]
artifacts_prefix = staging_match[1]
} else if (promoted_match !== null) {
core.info('Promoted artifacts has been selected')
const artifacts_tag = promoted_match[2]
myOutput = ''
await exec.exec('git', ['rev-list', '-n', '1', artifacts_tag], options)
artifacts_commit = myOutput
artifacts_prefix = promoted_match[1]
Expand All @@ -64,7 +65,7 @@ export async function promote(inputs: InputsArtifacts): Promise<void> {

const promoted_name = `${artifacts_prefix}promoted-${inputs.tag}`
const final_url: string = new URL(
path.join('/copy/', inputs.workflow_name, promoted_name),
path.join('/copy/', inputs.name, promoted_name),
inputs.url
)
.toString()
Expand All @@ -77,10 +78,13 @@ export async function promote(inputs: InputsArtifacts): Promise<void> {
maxBodyLength: Infinity,
maxContentLength: Infinity
}
core.info(`copying '${inputs.name}' to '${promoted_name}'`)
const response = await axios.get(final_url, request_config)
if (response.status !== 200 || !response.data.includes('BUILD COPIED')) {
throw Error(`Build not copied, ${response.status}: ${response.data}`)
}
core.info(`'${inputs.name}' has been copied to '${promoted_name}'`)

await setOutputs(promoted_name, inputs.url)
await setNotice(promoted_name, inputs.url)
}
Expand All @@ -89,14 +93,14 @@ export async function prolong(inputs: InputsArtifacts): Promise<void> {
const name_regex = new RegExp(
'(^[^/]+:)staging(-[0-9a-f]+.[^./]+.[0-9]+.[0-9]+)$'
)
const match = inputs.workflow_name.match(name_regex)
const match = inputs.name.match(name_regex)
if (match == null) {
throw Error('The name is not one of Scality actions artifacts')
}
const artifacts_target = `${match[1]}prolonged${match[2]}`

const final_url: string = new URL(
path.join('/copy/', inputs.workflow_name, artifacts_target),
path.join('/copy/', inputs.name, artifacts_target),
inputs.url
)
.toString()
Expand All @@ -109,13 +113,15 @@ export async function prolong(inputs: InputsArtifacts): Promise<void> {
maxBodyLength: Infinity,
maxContentLength: Infinity
}
core.info(`copying '${inputs.workflow_name} to '${artifacts_target}`)
core.info(`copying '${inputs.name} to '${artifacts_target}`)
const response = await axios.get(final_url, request_config)
if (response.status !== 200 || !response.data.includes('BUILD COPIED')) {
throw Error(`Build not copied, ${response.status}: ${response.data}`)
}
await setOutputs(inputs.workflow_name, artifacts_target)
await setOutputs(inputs.url, artifacts_target)
core.info(`'${inputs.name}' has been copied to '${artifacts_target}'`)

await setOutputs(artifacts_target, inputs.url)
await setNotice(artifacts_target, inputs.url)
}

async function upload_one_file(
Expand Down

0 comments on commit 0233a68

Please sign in to comment.