|
| 1 | +name: Initialize releases |
| 2 | + |
| 3 | +on: [push] |
| 4 | + |
| 5 | +jobs: |
| 6 | + initialize: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + permissions: |
| 9 | + contents: write |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v4 |
| 12 | + - name: mirror Git for Windows' Pacman repository to GitHub releases |
| 13 | + uses: actions/github-script@v7 |
| 14 | + env: |
| 15 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 16 | + with: |
| 17 | + script: | |
| 18 | + const makeList = require('./make-list.js') |
| 19 | + const list = makeList() |
| 20 | +
|
| 21 | + const ChildProcess = require('child_process') |
| 22 | + const run = (cmd, args) => { |
| 23 | + const { error, status, stderr, stdout } = ChildProcess.spawnSync(cmd, args, { stdio: 'inherit' }) |
| 24 | + if (error) { |
| 25 | + throw error |
| 26 | + } |
| 27 | + if (status !== 0) { |
| 28 | + throw new Error(`${cmd} ${args.join(' ')} exited with status ${status} (stderr: ${stderr})`) |
| 29 | + } |
| 30 | + return stdout |
| 31 | + } |
| 32 | +
|
| 33 | + const baseURL = 'https://wingit.blob.core.windows.net/' |
| 34 | + const targets = [] |
| 35 | + for (const release of list) { |
| 36 | + console.log(JSON.stringify(release, null, 2)) |
| 37 | + for (name of release.names) { |
| 38 | + const target = name.replace(/.*\//, '') |
| 39 | + console.log(`downloading ${baseURL}${name} to ${target}`) |
| 40 | + // call on curl to download the file |
| 41 | + run('curl', ['-sfLo', target, `${baseURL}${name}`]) |
| 42 | + targets.push(target) |
| 43 | + } |
| 44 | +
|
| 45 | + console.log(`creating release ${release.date}`) |
| 46 | + // call GitHub CLI to upload the files to a new release |
| 47 | + run('gh', [ |
| 48 | + 'release', |
| 49 | + 'create', |
| 50 | + '-R', |
| 51 | + '${{ github.repository }}', |
| 52 | + '--title', |
| 53 | + (new Date(release.date)).toString(), |
| 54 | + release.date, |
| 55 | + ...targets]) |
| 56 | + break |
| 57 | + } |
| 58 | +
|
0 commit comments